Numpy拆分多维数组

mrQ*_*RTY 4 python numpy multidimensional-array

我有一个要根据特定列拆分的多维numpy数组。

例如 [[1,0,2,3],[1,2,3,4],[2,3,4,5]] 说我想用表达式用第二列分割这个数组x <=2。然后我将得到两个数组[[1,0,2,3],[1,2,3,4]][[2,3,4,5]]

我当前正在使用此语句,我认为这是不正确的。

splits = np.split(S, np.where(S[:, a] <= t)[0][:1]) #splits S based on t

#a is the column number
Run Code Online (Sandbox Code Playgroud)

ora*_*nge 5

>>> import numpy as np
>>> a = np.asarray([[1,0,2,3],[1,2,3,4],[2,3,4,5]])
>>> a
array([[1, 0, 2, 3],
       [1, 2, 3, 4],
       [2, 3, 4, 5]])
>>> split1 = a[a[:,1] <= 2, :]
array([[1, 0, 2, 3],
       [1, 2, 3, 4]])
>>> split2 = a[a[:,1] > 2, :]
array([[2, 3, 4, 5]])
Run Code Online (Sandbox Code Playgroud)