在对数据进行处理时候,常见以下函数
np.newaxis(), np.ndim(), np.tile(), np.repeat(), np.view(), np.astype(), np.dtype(),
(1)np.newaxis() ------作用:增加维数
例子如下:
>>> import numpy as np
>>> x = np.array([1,2,3,4])
>>> y = x[np.newaxis ,:,np.newaxis]
>>> z = x[np.newaxis ,:]
>>> print(x.shape, y.shape, z.shape)
(4,) (1, 4, 1) (1, 4)
>>> x
array([1, 2, 3, 4])
>>> y
array([[[1],
[2],
[3],
[4]]])
>>> z
array([[1, 2, 3, 4]])
可以对已有数据通过np.newaxis函数对位置进行升维
(2)np.ndim-----作用:输出数组维数
>>> x.ndim
<