在python中使用numpy重新排列数组元素

时间:2013-11-09 05:30:34

标签: python arrays numpy

如何从旧数组(OLD)获取新数组(NEW)?

import numpy as np
OLD=np.array([1,4,7,2,5,8,3,6,9])

NEW = [[1,2,3],[4,5,6],[7,8,9]]

NEW = OLD.reshape (???

1 个答案:

答案 0 :(得分:3)

你的意思是这样吗?

>>> import numpy as np
>>> OLD = np.array([1,4,7,2,5,8,3,6,9])
>>> OLD.reshape((3, 3), order='F')
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])