Python numpy Ndarray 数组形状改变 reshape
使用 reshape : 不能直接改变调用 Ndarray 数组对象的形状,只能间接将改变的内容赋值给新的变量:
import numpy
as np
a
= np
.arange
(20)
print(a
)
print(a
.ndim
)
b
= a
.reshape
(2, 5, 2)
print(b
)
print(b
.ndim
)
print(a
)
print(a
.ndim
)
结果:
import numpy
as np
a
= np
.arange
(20)
print(a
)
print(a
.ndim
)
b
= a
.reshape
(2, 5, 2)
print(b
)
print(b
.ndim
)
print(a
)
print(a
.ndim
)
转载请注明原文地址:https://tech.qufami.com/read-9553.html