Deleting Row In Numpy Array Based On Condition January 23, 2024 Post a Comment I have a 2D numpy array of shape [6,2] and I want to remove the subarrays with the third element containing 0. array([[0, 2, 1], #Input [0, 1, 1], [1, 1, 0], [Solution 1: You can use boolean indexing.In [413]: x[x[:, -1] != 0] Out[413]: array([[0, 2, 1], [0, 1, 1], [1, 0, 2], [2, 1, 2]]) Copyx[:, -1] will retrieve the last columnx[:, -1] != 0 returns a boolean maskUse the mask to index into the original array Share Post a Comment for "Deleting Row In Numpy Array Based On Condition"
Post a Comment for "Deleting Row In Numpy Array Based On Condition"