网站首页 文章专栏 python numpy reshape 详解
python numpy reshape 详解
创建于:2019-06-18 07:50:04 更新于:2021-10-16 03:28:30 羽瀚尘 415
python python

按行reshape order='C' 按列reshape order='F'

temp = np.array([[1,2,3],[4,5,6]])
temp
# array([[1, 2, 3],
#       [4, 5, 6]])
temp.reshape((3,2))
# array([[1, 2],
#       [3, 4],
#       [5, 6]])
temp.reshape((3,2),'F')
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'tuple' object cannot be interpreted as an integer
temp.reshape((3,2),order='F')
# array([[1, 5],
#       [4, 3],
#       [2, 6]])
temp.reshape((3,2),order='A')
# array([[1, 2],
#      [3, 4],
#       [5, 6]])

reshape(a, newshape, order='C') Gives a new shape to an array without changing its data.

Parameters