I have arrays that are simple numpy.ndarrays
while other times the same variable may be a masked array. I'd like to figure out the most effective way to check if there are data in the array and that ALL are not masked
I've got the below to illustrate:
data0 = np.ma.array([3,3,3,3,3], mask=[True, True, False, True, True])
data1 = np.ma.array([3,3,3,3,3], mask=[True, True, True, True, True])
data2 = np.array([3,3,3,3,3])
for dataNum, data in enumerate([data0, data1, data2]):
if (isinstance(data, np.ma.masked_array) and not data.mask.all()) or (isinstance(data,np.ndarray)):
print('if statement passed data{}'.format(dataNum))
but this allows for all 3 to pass. I assume because a masked_array
is considered an ndarray
if statement passed data0
if statement passed data1
if statement passed data2
i'd like for data0 and data2 to pass so I can operate on the data. Ideally it's something simple too :)