YDOOK:Python numpy Ndarray 数组形状改变 reshape

tech2023-02-10  94

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)
最新回复(0)