[Numpy-discussion] slicing / indexing question
Wed Sep 22 10:46:19 CDT 2010
On Tue, Sep 21, 2010 at 6:20 PM, Timothy W. Hilton <email@example.com>wrote:
> I have an indexing problem which I suspect has a simple solution, but
> I've not been able to piece together various threads I've read on this
> list to solve.
> I have an 80x1200x1200 nd.array of floats this_par. I have a
> 1200x1200 boolean array idx, and an 80-element float array pars. For
> each element of idx that is True, I wish to replace the corresponding
> 80x1x1 slice of this_par with the elements of pars.
> I've tried lots of variations on the theme of
> >>>this_par[idx[np.newaxis, ...]] = pars[:, np.newaxis, np.newaxis]
> but so far, no dice.
> Any help greatly appreciated!
This is a tough indexing question for me. I can visualize the arrays and the
required selections in my mind, but hard to put them into application as in
this case. Beyond 2D array operations indexing and broadcasting operations
get somewhat complex to interpret at the first look and likewise later when
I read and decipher my own code, not to mention if someone else wants to
understand that same code.
What do you do with such big arrays? It is good to see new atmospheric
sciences people in the lists. Our department is still swarming with IDL and
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion