[Tutor] change values in an array

questions anon questions.anon at gmail.com
Thu Nov 17 06:02:06 CET 2011


I am trying to do something really simple.
I have a numpy array and if any values in the array are 255 I want to
change them to 1.
but I can't seem to get anything to work!

If I use:

for i, value in enumerate(mask_arr):
    if value==255:
        mask_arr[i]=1

I get this error:

Traceback (most recent call last):
  File "d:/timeseries_mask.py", line 51, in <module>
    if value==255:
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()

and if I try to add a.any() to my code:

for i, value in enumerate(mask_arr):
    if value.any()==255:
        mask_arr[i]=1

my array does not change at all.
Any feedback will be greatly appreciated
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111117/4856cbf5/attachment.html>


More information about the Tutor mailing list