S.EB
S.EB

Reputation: 2226

numpy array IndexError: 'index out of bound' when a mask is inverted or negated

I have 2 arrays one is mask and the other is the labels:

Both arrays have the same shape:

(Pdb) L.shape
(178, 201, 101)
(Pdb) MASK.shape
(178, 201, 101)

when it reaches to this line:

L[~MASK] = 0 
IndexError: 'index 255 is out of bounds for axis 0 with size 178'

it shows an error that I could not find any reason for that. Could you please help me with this?

Upvotes: 0

Views: 159

Answers (1)

fountainhead
fountainhead

Reputation: 3722

Try:

L[np.logical_not(MASK)]

The ~ (tilde) operator you are using is a bitwise complement operator, not a logical negation operator.

Upvotes: 1

Related Questions