[Tutor] reclassify values in an array
questions anon
questions.anon at gmail.com
Thu Sep 1 01:17:45 CEST 2011
Dear All,
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.
Attempt 1:
big_array=N.ma.concatenate(all_FFDI)
for i in big_array:
if i<100:
i=0
elif i>=100:
i=1
print big_array
sum=big_array.sum(axis=0)
print "the sum is", sum
Attempt 2:
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
sum=big_array.sum(axis=0)
print "the sum is", sum
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110901/a9258f4a/attachment.html>
More information about the Tutor
mailing list