Home > database >  Removing None's array from numpy array
Removing None's array from numpy array

Time:05-25

I have numpy array

a = np.array([[None, None],[72,10][None,None][77,10]])

I would like remove [None, None] from numpy array.

Is there an efficient way to remove Nones array from numpy arrays and resize the array ?

I would like have array:

array([72,10],[77,10]])

CodePudding user response:

You can use boolean indexing by selecting the rows where all values are not None:

out = a[(a!=None).all(1)].astype(int)

output:

array([[72, 10],
       [77, 10]])

CodePudding user response:

import numpy as np
a = np.array([[None, None],[72,10],[None,None],[77,10]])
L = []
for i in a:
    if None not in i :
        L.append(i)

print(np.array(L))
  • Related