[Numpy-discussion] efficient sum of "sparse" 2D arrays?

Kuzminski, Stefan R SKuzminski at fairisaac.com
Mon Jan 26 04:54:03 CST 2004

Could you use masked arrays more efficiently in this case? If you create
the array so that values >255 and <0 are masked, then they will be
excluded from the sum ( and from any other operations as well ).


-----Original Message-----
From: numpy-discussion-admin at lists.sourceforge.net
[mailto:numpy-discussion-admin at lists.sourceforge.net] On Behalf Of
Konrad Hinsen
Sent: Monday, January 26, 2004 12:17 AM
Cc: numpy-discussion at lists.sourceforge.net
Subject: Re: [Numpy-discussion] efficient sum of "sparse" 2D arrays?

On 26.01.2004, at 07:14, RJS wrote:

> The problem: I have a "stack" of 8,  640 x 480 integer image arrays 
> from a FITS cube concatenated into a 3D array, and I want to sum each 
> pixel such that the result ignores clipped values (255+); i.e., if two

> images have clipped pixels at (x,y) the result along z will be the sum

> of the other 6.
Memory doesn't seem critical for such small arrays, so you can just do

sum([where(a < 255, a, 0) for a in images])


The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net

More information about the Numpy-discussion mailing list