I read most of How to convert a boolean array to an int array , but I still lost how (most efficiently) to convert a numpybool to an int array, but with different values. For example, I have:
>>> k=np.array([True, False, False, True, False])
>>> print k
[ True False False True False]
I would like this to be converted to an array where True says 2 and False - 5.
Of course, I can always establish a linear equation:
>>> print 5-k*3
[2 5 5 2 5]
... which, being vectorized, uselessly uses both addition (subtraction) and multiplication; furthermore, if I need the opposite values (5 for True and 2 for False), I basically have to use (and recount) another equation:
>>> print 2+k*3
[5 2 2 5 2]
... for me it is a reading problem.
, /, numpy. ?