[Tutor] reclassify values in an array

Alan Gauld alan.gauld at btinternet.com
Thu Sep 1 01:41:19 CEST 2011

On 01/09/11 00:17, questions anon wrote:
> 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,...
> And then finally sum them together.

And what has been the problem?

> I have attempted a few methods, see code below.

I'm not familiar with NumPy (which I assume is what you are using?)
However the second approach looks more likely to succeed than the first. 
Assuming enumerate works with NumPy arrays. Is there any
reason why you cannot use a normal list?

Then it would just be:

result = sum(1 for item in array if item >= 100)


Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list