Numpy可以简单的操作数组与创建矩阵。
ndarray.shape 表示数组的维度,返回一个元组,这个元组的长度就是维度的数目,即 ndim 属性(秩)。比如,一个二维数组,其维度表示"行数"和"列数"。
同时,shape属性也是一个可写属性,可以对其进行操作数组长度。
shape属性调整数组大小
import numpy as np
a = np.array([[1,2,3],[4,5,6]])
print (a)
a.shape = (3,2)
print (a)
reshape 函数调整数组大小
import numpy as np
a = np.array([[1,2,3],[4,5,6]])
print (a)
b = a.reshape(3,2)
print (b)