一维数组的重塑
将一行或一列的数组转换为多行多列的数组
from numpy import array
a=array([1,2,3,4,5,6,7,8,9,10])
b=a.reshape(5,2)
c=a.reshape(2,5)
print(b)
print(c)
结果:
多维数组的重塑
from numpy import array
a=array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
b=a.reshape(4,3)
c=a.reshape(2,6)
print(b)
print(c)
结果:
将多维数组转换为一维数组
from numpy import array
a=array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
print(a.flatten())
print(a.ravel())
结果:
数组的转置
from numpy import array
from numpy.ma import transpose
a=array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
print(a)
print(a.T)
b=transpose(a)
print(b)
结果: