Antonis
Antonis

Reputation: 361

Delete array from 2D array

I have a 2D array like this:

 [array([71, 35, 44,  0])
 array([56, 55,  0])
 array([32, 90, 11])
 array([ 0,  3, 81,  9, 20])
 array([0, 0]) array([0, 0]) array([0, 0]) array([ 5, 89])]

and I want to remove [0, 0]

I try to

myarray = np.delete(myarray, np.where(myarray == [0, 0]), axis=0)

but it doesnt work.

How can I remove [0, 0] ?

Upvotes: 2

Views: 1250

Answers (2)

Mohsen Hrt
Mohsen Hrt

Reputation: 303

If you have numpy array to delete first row of a 2d array: insert axis=0 to remove rows and axis=1 to remove columns

array2d=np.delete(array2d, 0, axis=0)

Upvotes: 1

user3483203
user3483203

Reputation: 51155

Use a list comprehension with np.array_equal:

>>> [i for i in arr if not np.array_equal(i, [0,0])]

[array([71, 35, 44,  0]),
 array([56, 55,  0]),
 array([32, 90, 11]),
 array([ 0,  3, 81,  9, 20]),
 array([ 5, 89])]

However, it is best to not work with jagged numpy arrays, as numpy does not behave well with such arrays.

Upvotes: 3

Related Questions