Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return the indices of "false" values in a boolean array

I feel like this is a really simple question but I can't find the solution.

Given a boolean array of true/false values, I need the output of all the indices with the value "false". I have a way to do this for true:

test = [ True False True True]

test1 = np.where(test)[0]

This returns [0,2,3], in other words the corresponding index for each true value. Now I need to just get the same thing for the false, where the output would be [1]. Anyone know how?

like image 641
Melanie Avatar asked Oct 17 '25 11:10

Melanie


1 Answers

Use np.where(~test) instead of np.where(test).

like image 75
no comment Avatar answered Oct 20 '25 02:10

no comment