flipping specific bits in numeric array
les ander
les_ander at yahoo.com
Sun Oct 6 13:34:57 EDT 2002
Hi,
suppose i have a numeric array of 1's and 0's and i would like
to flip the 1's --> 0's for only selected entries:
for example
state=array([1,0,0,0,1])
a=array([0.4,0.2,0.5,0.8,0.8])
I_a=nonzero(a<0.5) # I would like to flip bits for entries of "state"
# at index in I_a
for i in I_a:
if state[i]==0: state[i]=1
else: state[i]=0
is there are faster way? thanks
furthermore, is it possible to overload the "not" operator for
numeric so that the i could achieve the above with simply "not a"?
thanks
p.s. I know what numarray has array indexing, however, i don't
want to use numarray since i am using MLab which does not seem to support
numarray
More information about the Python-list
mailing list