I have an array which looks like this
[1, 0, 1 , 0 , 0, 1]
And I want to get those indexes that have 1 in it. So here I would get an array of <
Here's one compact way -
2**np.where(a)[0]
Sample run -
In [83]: a = np.array([1, 0, 1 , 0 , 0, 1]) In [84]: 2**np.where(a)[0] Out[84]: array([ 1, 4, 32])