当前位置: 代码迷 >> 综合 >> np的reshape函数
  详细解决方案

np的reshape函数

热度:21   发布时间:2024-02-23 03:02:01.0

1、np.shape函数

np.reshape(a, newshape, order='C')

a:Array to be reshaped.

newshape:int or tuple of ints

order:{'C', 'F', 'A'}, optional

2、实例

np.arange(6)

值:array([0, 1, 2, 3, 4, 5])

a = np.arange(6).reshape((3, 2))

将a转化为3*2的形状

array([[0, 1],
       [2, 3],
       [4, 5]])

3、转化规则

形状变化是基于数组元素不能改变的,变成的新形状中所包含的元素个数必须符合原来元素个数。如果数组元素发生变化的时候,就会报错: