一、reshape
a = np.array([[1,2,3,4],
[5,6,7,8],
[9,10,11,12]])
print(a)
b = np.reshape(a,(12,1))
print(b)
print(a)
结果为
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
[[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[ 6]
[ 7]
[ 8]
[ 9]
[10]
[11]
[12]]
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
所以,使用np.reshape(array,shape)不改变原始矩阵的shape,同时有返回值
a = np.array([[1,2,3,4],
[5,6,7,8],
[9,10,11,12]])
print(a)
b = a.reshape(12,1)
print(b)
print(a)
使用 a.reshape(shape)形式时,结果一样。
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
[[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[ 6]
[ 7]
[ 8]
[ 9]
[10]
[11]
[12]]
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
二、resize
1.numpy中
a = np.array([[1,2,3,4],
[5,6,7,8],
[9,10,11,12]])