numpy.linspace(start, stop, num=50, endpoint=True, retstep=False)
start 起始位置
stop 终止位置
num 个数
endpoint 终止位置是否计算
是否返回步长
np.linspace(0, 1, 5)
array([ 0. , 0.25, 0.5 , 0.75, 1. ])
numpy.arange([start, ]stop, [step, ]dtype=None)
start=None, stop=None, step=None, dtype=None)
>>> np.arange(3) array([0, 1, 2]) >>> np.arange(3.0) array([ 0., 1., 2.]) >>> np.arange(3,7) array([3, 4, 5, 6]) >>> np.arange(3,7,2) array([3, 5])
numpy.meshgrid()
需要XY平面的网格数据,这就是meshgrid函数所实现的内容
>>> x=[1,2,3]
>>> y=[10,11,12,13,14]
>>> X,Y=np.meshgrid(x,y)
>>> X
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
>>> Y
array([[10, 10, 10],
[11, 11, 11],
[12, 12, 12],
[13, 13, 13],
[14, 14, 14]])
其网格示意如下,其中XY平面中网格的交点就是上面的X和Y数据值。
numpy.c
Translates slice objects to concatenation along the second axis.
>>> np.c_[1,2,2]
array([[1, 2, 2]])
>>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
array([[1, 2, 3, 0, 0, 4, 5, 6]])
在第2轴上连接数组
numpy.reshape(a, newshape, order='C')
Gives a new shape to an array without changing its data.[不改变数据的情况下改变矩阵的行列]
>>> a = np.arange(6)
>>> a
array([0, 1, 2, 3, 4, 5])
>>> a.reshape((3,2))
array([[0, 1],
[2, 3],
[4, 5]])
>>> np.reshape(np.ravel(a), (2, 3))
array([[0, 1, 2],
[3, 4, 5]])
>>> np.reshape(a, (2, 3), order='F')
array([[0, 2, 4],
[1, 3, 5]])
>>> np.reshape(np.ravel(a, order='F'), (2, 3), order='F')
array([[0, 2, 4],
[1, 3, 5]])
>>> a = np.array([[1,2,3], [4,5,6]])
>>> np.reshape(a, 6)
array([1, 2, 3, 4, 5, 6])
>>> np.reshape(a, 6, order='F')
array([1, 4, 2, 5, 3, 6])
>>> np.reshape(a, (3,-1))
array([[1, 2],
[3, 4],
[5, 6]])
numpy.ravel(a, order='C')
Return a contiguous flattened array.
返回一个连续的扁平数组。
order : {‘C’,’F’, ‘A’, ‘K’}, optional
等价于:reshape(-1, order=order).
>>> x = np.array([[1, 2, 3], [4, 5, 6]])
>>> np.ravel(x)
array([1, 2, 3, 4, 5, 6])
np.hstack
Stack arrays in sequence horizontally (column wise).[水平扩展数组(列方式)]
取一个数组序列,并水平堆叠,形成一个数组。 重建数组除以hsplit。
a = np.array([[1],[2],[3]])b = np.array([[2],[3],[4]])c = np.array([[3],[4],[5]])np.hstack((a,c,b))#------------array([[1, 3, 2], [2, 4, 3], [3, 5, 4]])
>>> a = np.array((1,2,3))
>>> b = np.array((2,3,4))
>>> np.hstack((a,b))
array([1, 2, 3, 2, 3, 4])
numpy.c
将切片对象转换为沿着第二个轴的连接。
>>> np.c_[np.array([1,2,3]), np.array([4,5,6])]
array([[1, 4],
[2, 5],
[3, 6]])
>>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
array([[1, 2, 3, 0, 0, 4, 5, 6]])