Issue
I have a numpy array with multiple rows, I want to delete the rows with index 0, 1, 2 and 6 +0, 6+1, 6+2, and 2 * 6+0, 2 * 6+1, and 2 * 6+2, and ... c * 6+0, c * 6+1, c * 6+2. I know that is possible to use the np.delete
, however I don't know how to loop over the different indices. Here is an example:
a = np.array([[4, 5],
[4, 2],
[1, 2],
[2, 3],
[3, 1],
[0, 1],
[1, 1],
[1, 0],
[1, 5],
[5, 4],
[2, 3],
[5, 5]])
The output which I want is :
out = np.array([
[2, 3],
[3, 1],
[0, 1],
[5, 4],
[2, 3],
[5, 5]])
Solution
Instead of deleting, you could filter them out:
out = a[~np.isin(np.arange(len(a))%6, [0,1,2])]
Output:
array([[2, 3],
[3, 1],
[0, 1],
[5, 4],
[2, 3],
[5, 5]])
Answered By - enke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.