np.ceil(多维数组):对多维数组的各个数向上取整

np.floor(多维数组):对多维数组的各个数向下取整

np.expand_dims(x,axis = 0):在x的第一维度上插入一个维度,axis=1,在x的第二个维度上插入一个维度

例如:

x = np.array([[1,2,3],[4,5,6]])
print (x)
print (x.shape)

结果:

[[1 2 3]
[4 5 6]]
(2, 3)

axis = 0:

y = np.expand_dims(x,axis=0)
print (y)
print ("y.shape: ",y.shape)
print ("y[0][1]: ",y[0][1])

[[[1 2 3]
[4 5 6]]]
y.shape: (1, 2, 3)
y[0][1]: [4 5 6]

axis = 1:

y = np.expand_dims(x,axis=1)
print (y)
print( "y.shape: ",y.shape)
print ("y[1][0]: ",y[1][0])

结果:

[[[1 2 3]]

[[4 5 6]]]
y.shape: (2, 1, 3)
y[1][0]: [4 5 6]

np.concatenate()

np.concatenate((np.arange(6), np.arange(5, -1, step=-1)))

结果:

[0 1 2 3 4 5 5 4 3 2 1 0]

np.squeeze()函数可以删除数组形状中的单维度条目,即把shape中为1的维度去掉,但是对非单维的维度不起作用。

np.mod():x1 % x2,结果符号和x2的符号相同,x1,x2均为正数时,结果为其余数,有一个为负数时,结果为相除后的向下取整+x2的符号

print(np.mod(-5,3)) 
print(np.mod(5,2))
print(np.mod(5, 1))
print(np.mod(5, -3))
结果:

1
1
0
-1

np.any(weights, axis=0):axis = 0,表示列,某一列有一个为真即为真,axis=1:表示行,有一个为真即为真

np.nonzero():返回非零元素的位置

#a是2维数组
a = np.array([[0,0,3],[0,0,0],[0,0,9]])
b = np.nonzero(a)
print(np.array(b).ndim)
print(b)
print(np.transpose(np.nonzero(a)))
结果:
2
(array([0, 2], dtype=int64), array([2, 2], dtype=int64))
[[0 2]
[2 2]]

 

numpy-np.ceil,np.floor,np.expand_dims方法的更多相关文章

  1. 数学对象Math ceil()、floor()、round()方法

      Math.ceil()   功能:对一个数进行上取整. 语法:Math.ceil(x) 参数: x:一个数值. 返回值:返回大于或等于x,并且与之最接近的整数. 注:如果x是正数,则把小数“入”: ...

  2. JavaScript里Math对象的ceil()、floor()、round()方法的区别

    ceil(x) 官方含义:对一个数进行上舍入.理解:ceiling为天花板的意思,意译为向上取整.即取得大于于等于x的最大整数. floor(x) 官方含义:对一个数进行下舍入.理解:floor为地板 ...

  3. python中numpy库ndarray多维数组的的运算:np.abs(x)、np.sqrt(x)、np.modf(x)等

    numpy库提供非常便捷的数组运算,方便数据的处理. 1.数组与标量之间可直接进行运算 In [45]: aOut[45]:array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ ...

  4. 【NumPy】 之常见运算(np.around、np.floor、np.ceil、np.where)

    aroundnp.around 返回四舍五入后的值,可指定精度. around(a, decimals=0, out=None) a 输入数组 decimals 要舍入的小数位数. 默认值为0. 如果 ...

  5. 【NumPy】 之常见运算(np.around、np.floor、np.ceil、np.where)(转)

    原博客链接:https://blog.csdn.net/tz_zs/article/details/80775256 np.around: 四舍五入取整 n = np.array([-0.746, 4 ...

  6. 浮点型数据需要转化为int,才能作为点,被读取abc = np.array(abc, dtype=np.int)

    import cv2 import numpy as np import matplotlib.pyplot as plt img = 'test.jpg' img = cv2.imread(img) ...

  7. (数学)P、NP、NPC、NP hard问题

    概念定义: P问题:能在多项式时间内解决的问题: NP问题:(Nondeterministic Polynomial time Problem)不能在多项式时间内解决或不确定能不能在多项式时间内解决, ...

  8. Math类中round、ceil和floor方法的功能

    Java中的Math工具类用来完成除+.-.*./.%等基本运算以外的复杂运算,位于java.lang包下,Math类的构造器全是私有的(private),因此无法创建Math类的对象,Math类的方 ...

  9. PHP 浮点数 转化 整数方法对比 ceil,floor,round,intval,number_format

    ceil,floor,round,intval,number_format - 执行1000W此效率对比 Header("Content-Type:text/html;charset=utf ...

随机推荐

  1. 201871010119-帖佼佼《面向对象程序设计(java)》第十三周学习总结

    博客正文开头格式: 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nw ...

  2. MySQL必知必会-官方数据库表及SQL脚本导入生成

    最近在复习SQL语句,看的是MySQL必知必会这本书,但是发现附录中只有表设计,没有表的具体数据.所以在学习相应的语句中体验不是很好,去网上查了数据库的内容,自己慢慢导入到了数据库中.把表放出来作为参 ...

  3. hdu 1255 覆盖的面积 (扫描线求矩形交)

    覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. python并发之多进程

    #mutiprocessing模块 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.Pytho ...

  5. idea 几个常用的设置

    一.主题的背景

  6. Redis来啦~~

    一. 先聊点别的 1. sql & nosql sql指关系型数据库,如Oracle,MySQL等,nosql泛指非关系型数据库,如MongoDB,Redis等:SQL数据存在特定结构的表中, ...

  7. adb shell常用命令

    一.文件操作相关命令 1.文件操作命令 子命令 参数 说明 cd 无 进入目录 cat [-beflnstuv] [-B bsize] [file...] 查看文件内容-n:显示行号-b:显示行号,但 ...

  8. Please ensure the argon2 header and library are installed

    在CentOS上安装libargon2和libargon2-devel即可 yum install -y libargon2 libargon2-devel

  9. Nmap参数详解(含扫描参数原理解释)

    语法结构:nmap [Scan Type(s)] [Options] {target specification} 端口状态介绍 open:确定端口开放,可达 closed :关闭的端口对于nmap也 ...

  10. vue-element-admin在install的时候关于sass的错误信息

    vue-element-admin在install的是报关于sass的错误信息 今天使用vue-element-admin给自己弄的一个微信小程序编写一个后台管理系统的时候,报关于sass的错误,下载 ...