[SciPy-user] extracting elements of a matrix using arrays as indices

Alan G Isaac aisaac@american....
Wed May 21 14:29:35 CDT 2008

On Tue, May 20, 2008 at 9:43 PM, Michael Hearne <mhearne@usgs.gov> wrote:
> Neilen - Thanks.  Unfortunately, I've either discovered 
> a bug or have failed to understand how to use this 
> function.  The below code snippet:
> from pylab import * 
> import numpy 
> print numpy.__version__, numpy.__file__ 
> data = rand(648,690)
> i,j = (data < 0.14).nonzero()
> data[ix_(i,j)] = data[ix_(i,j)]*0 

I believe your problem is with ``data[ix_(i,j)]``.
Let's say that i and j are about 60,000 in length.
So you are trying to create a 60k × 60k array,
which has 3600M elements. I'm guessing you do not
have enough memory for this. Otherwise, it should
work (although it is very wasteful).

Alan Isaac

More information about the SciPy-user mailing list