网站首页 文章专栏 python numpy reshape 详解
按行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