Python和Numpy中的常用操作
print(type(X))
print(type(X),X.ndim,X.shape)
print(X.size,X.itemsize,X.nbytes)
print(X.ndim,X.shape,X.strides)
print(X.base,X.flags)
Numpy中数值范围操作
range(start, end, step),返回一个list对象,起始值为start,终止值为end,但不含终止值,步长为step。只能创建int型list。
arange(start, end, step),与range()类似,但是返回一个array对象。需要引入import numpy as np,并且arange可以使用float型数据。
numpy手册中函数:
Arange: uses a step size
Linspace:uses number of samples
Logspace:Samples uniformly with endpoints specifiedusing log and base
Geomspace:with endpoints specified directly
Meshgrid返回X,Y矩阵
Mgrid返回stacked坐标矩阵
Ogrid返回list(x vector,yvector)
Numpy中数组遍历迭代器nditer
Numpy中对于一维数组没有行列的概念
上面a,b的shape为(3,),结果数组为(1,3,2)
下面a,b的shape为(1,3),结果数组为(3,1,2)
Numpy中创造空数组ndarray对象
t=np.array([])
Numpy中非零nonzero函数
numpy.nonzero(a)
numpy.count_nonzero(a,axis=None)