Suppose we have a dataset like this:
X =
6 2 1
-2 4 -1
4 1 -1
1 6 1
2 4 1
6 2 1
I would like to get two data from this one having last digit 1 and another having last digit -1.
X0 =
-2 4 -1
4 1 -1
And,
X1 =
6 2 1
1 6 1
2 4 1
6 2 1
How can we do this in numpy efficiently?
In simple python, I could do this like this:
dataset = np.loadtxt('data.txt')
X0, X1 = [], []
for i in range(len(X)):
if X[i][-1] == 1:
X0.append(X[i])
else:
X1.append(X[i])
This is slow and cumbersome, Numpy is fast and easy so, I would appreciate if there is easier way in numpy. Thanks.