1. reshape
arr = arr.reshape(shape)
import numpy as np
reshapeArr = np.arange(1, 10, 1)
print(reshapeArr) # [1 2 3 4 5 6 7 8 9]
newArr = reshapeArr.reshape((3, 3))
print(newArr)
# [[1 2 3]
# [4 5 6]
# [7 8 9]]
' 注意如果改变reshape前的数组的值,reshape之后的数组也会被改变,相当于reshape并没有修改数据内存存储位置 '
reshapeArr[0] = 0
print(reshapeArr) # [0 2 3 4 5 6 7 8 9]
print(newArr)
# [[0 2 3]
# [4 5 6]
# [7 8 9]]
newArr[0][1] = 22
print(reshapeArr) # [0 22 3 4 5 6 7 8 9]
print(newArr)
# [[0 22 3]
# [4 5 6]
# [7 8 9]]