[SciPy-User] From 1-D boolean array to integer index

Alan G Isaac alan.isaac@gmail....
Tue Oct 11 14:25:54 CDT 2011


On 10/11/2011 1:29 PM, Jacob Biesinger wrote:
> I have a 1-D bool array which I'd like to convert to an integer index.

Sounds like you may be able to just use your bool array:

     >>> idx = np.array([True, False, True])
     >>> a = np.random.random(3)
     >>> a
     array([ 0.04818879,  0.49417941,  0.70470834])
     >>> a[idx]
     array([ 0.04818879,  0.70470834])

hth,
Alan Isaac



More information about the SciPy-User mailing list