[Tutor] reclassify values in an array
questions anon
questions.anon at gmail.com
Sat Sep 3 00:27:34 CEST 2011
thank you for all of the resonses, I have attempted all of the suggestions.
It is a numpy array so I can try another list if you would prefer but I
thought I would show the error anyway.
the error I am receiving is
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
on this code
big_array=N.ma.concatenate(all_FFDI)
for i, value in enumerate(big_array):
if value==100:
big_array[i]=0
elif value>=100:
big_array[i]=1
print big_array
On Thu, Sep 1, 2011 at 6:33 PM, Peter Otten <__peter__ at web.de> wrote:
> questions anon wrote:
>
> > I have been going round in circles trying to solve something that sounds
> > simple. I have a huge array and I would like to reclassify the values.
> > Firstly just make them zeros and ones, for example if the values in the
> > array are less than 100 make them 0 and if greater than 100 make them 1.
> > And then finally sum them together.
> > I have attempted a few methods, see code below. Any feedback will be
> > greatly appreciated.
>
> >>> import numpy
> >>> all_FFDI = numpy.arange(60).reshape((3,4,5))
> >>> all_FFDI
> array([[[ 0, 1, 2, 3, 4],
> [ 5, 6, 7, 8, 9],
> [10, 11, 12, 13, 14],
> [15, 16, 17, 18, 19]],
>
> [[20, 21, 22, 23, 24],
> [25, 26, 27, 28, 29],
> [30, 31, 32, 33, 34],
> [35, 36, 37, 38, 39]],
>
> [[40, 41, 42, 43, 44],
> [45, 46, 47, 48, 49],
> [50, 51, 52, 53, 54],
> [55, 56, 57, 58, 59]]])
> >>> all_FFDI >= 25
> array([[[False, False, False, False, False],
> [False, False, False, False, False],
> [False, False, False, False, False],
> [False, False, False, False, False]],
>
> [[False, False, False, False, False],
> [ True, True, True, True, True],
> [ True, True, True, True, True],
> [ True, True, True, True, True]],
>
> [[ True, True, True, True, True],
> [ True, True, True, True, True],
> [ True, True, True, True, True],
> [ True, True, True, True, True]]], dtype=bool)
> >>> (all_FFDI >= 25).sum()
> 35
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110903/97d2bbe5/attachment.html>
More information about the Tutor
mailing list