[SciPy-User] From 1-D boolean array to integer index
Jacob Biesinger
jake.biesinger@gmail....
Tue Oct 11 12:29:07 CDT 2011
Hi all!
This seems a trivial question, but I couldn't find it in the archives. I
have a 1-D bool array which I'd like to convert to an integer index. The
best I've come up with is:
>>> int(''.join(['1' if e else '0' for e in sp.array([True, False])]), 2)
2
>>> int(''.join(['1' if e else '0' for e in sp.array([True, False, True])]),
2)
5
Is there an easier way to do this?
Thanks!
--
Jake Biesinger
Graduate Student
Xie Lab, UC Irvine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20111011/1553faac/attachment.html
More information about the SciPy-User
mailing list