Skip to content Skip to sidebar Skip to footer

Small Clarification Needed On Numpy.any For Matrices

I am having a slight problem in getting numpy.any() to work fine on my problem. Consider I have a 3D matrix of N X M X M matrix, where I need to get rid of any matrix MXM that has

Solution 1:

In a 10x5x5 matrix with x[0,:,:] = 0 I would expect a result of:

[False,  True,  True,  True,  True,  True,  True,  True,  True,  True]

because it is the first of ten 5x5 arrays which is all zero and not of five.

You get this result using

x.any(axis=1).any(axis=1)

or

x.any(axis=2).any(axis=1)

which means you first eliminate the second (axis=1) or the third (asix=2) dimension and then the remaining second (axis=1) and you get the only one dimension, which was originally the first one (axis=0).

Post a Comment for "Small Clarification Needed On Numpy.any For Matrices"