2 回答

TA貢獻(xiàn)1799條經(jīng)驗 獲得超6個贊
您可以像這樣使用 numpy hsplit() 函數(shù):
>>> a=np.array([[0, 0, 0],
... [1, 1, 1]])
>>> b,c,d = np.hsplit(a,3)
>>> b
array([[0],
[1]])
>>> c
array([[0],
[1]])
>>> d
array([[0],
[1]])
使其成為三個數(shù)組的單個列表:
>>> myList = [*np.hsplit(a,3)]
>>> myList
[array([[0],
[1]]), array([[0],
[1]]), array([[0],
[1]])]

TA貢獻(xiàn)1859條經(jīng)驗 獲得超6個贊
使用列表推導(dǎo),您有 2 個選項:
import numpy as np
a = np.array([[0, 0, 0],
[1, 1, 1]])
[c for c in a.T]
[array([0, 1]), array([0, 1]), array([0, 1])]
[a[:,i] for i in range(a.shape[1])]
[array([0, 1]), array([0, 1]), array([0, 1])]
#or as hpaulj suggested in the comment
[a[:,[i]] for i in range(a.shape[1])]
[array([[0],[1]]),
array([[0],[1]]),
array([[0],[1]])]
添加回答
舉報