更改形状
np.array().shape:改变数组的形状
x = np.array([1, 2, 9, 4, 5, 6, 7, 8])
[1 2 9 4 5 6 7 8]
x.shape = [2, 4]
[[1 2 9 4]
[5 6 7 8]]
np.array().flat:将多维数组转换为一维,通过for循环遍历
x = np.array([[11, 12, 13, 14, 15],
[31, 32, 33, 34, 35]])
[[11 12 13 14 15]
[31 32 33 34 35]]
x.flat
for i in y:
print(i,end=' ')
13 19 25
np.array().flatten():将数组的副本转换为一维数组
order=''
'C' 按行,'F' 按列,'A' 原顺序,'k' 元素在内存中的出现顺序
np.ravel()与上同
numpy.reshape(a, newshape[, order=‘C’]):
不改变数据,而赋予新的形状
newshape[行,-1]:
此时-1表示为依据行数自动确认列数
newshape = -1时,表示降为一维
x = np.arange(12)
y = np.reshape(x, [3, -1