[Numpy-discussion] Memory errors

Vikalpa Jetly vjetly at i3.com
Fri Oct 6 08:30:51 CDT 2006

Thanks Travis and Robert. I am just getting my feet wet in numpy. Both
approaches i.e:

b = zeros_like(a)
b[a>200] = 1


b = (a > 200).astype(numpy.uint8)

avoid the memory error. Related question is that I need to test for multiple
conditions on the same array and set values to 1 or 0. I see that statements
like b[a>200 or a<50] = 1 do not work. So is the way to do this simply to
run a separate statement in the form b[condition]= 1 for each test?

Also since my output has to be a binary array, can the new array be defined
as binary type or nibble, potentially reducing memory overhead?


-----Original Message-----
From: numpy-discussion-bounces at lists.sourceforge.net
[mailto:numpy-discussion-bounces at lists.sourceforge.net] On Behalf Of Travis
Sent: Thursday, October 05, 2006 5:44 PM
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] Memory errors

The MemoryError is a direct result when system malloc fails.    Rather 
than use where with two scalars (you're resulting array will be int32 
and therefore 4-times larger).


b = zeros_like(a)
b[a>200] = 1

which will consume less memory.


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net

More information about the Numpy-discussion mailing list