Issue
I have 2D Numpy array, I would like to delete all rows that start with certain value let say (0), then keep all rows that start with other value let say (10) into new array
a1 = np.array([[ 0, 1, 2, 3, 4],
[ 5, 6, 0, 8, 0],
[10, 11, 12, 13, 14],
[ 0, 16, 17, 18, 19],
[20, 21, 22, 0, 24]])
after first step
a2 = ([[ 5, 6, 0, 8, 0],
[10, 11, 12, 13, 14],
[20, 21, 22, 0, 24]])
last step
a3 = ([[10, 11, 12, 13, 14]])
Solution
You can achieve this with the following masks:
mask = (a1[:, 0] != 0)
a2 = a1[mask, :]
mask2 = (a2[:, 0] == 10)
a3 = a2[mask2, :]
Answered By - iacob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.