### reclassify values in an array

2011-08-31 23:17:45 GMT

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

_______________________________________________ Tutor maillist - Tutor <at> python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor