Layered Multi-Dimensional Arrays

I have a numpy multidimensional array that I want to split based on a specific column.

Ex. [[1,0,2,3],[1,2,3,4],[2,3,4,5]] Let's say I want to split this array into a 2nd column with an expression x <=2. Then I would get two arrays [[1,0,2,3],[1,2,3,4]]and [[2,3,4,5]].

I am currently using this operator, which I believe is not true.

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

#a is the column number
+4
source share
1 answer
>>> 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]])
+4
source

Source: https://habr.com/ru/post/1629495/


All Articles