[Numpy-discussion] slicing / indexing question

Timothy W. Hilton hilton@meteo.psu....
Tue Sep 21 18:20:51 CDT 2010


Hello,

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!

Thanks,
Tim

--

Timothy W. Hilton
PhD Candidate, Department of Meteorology
The Pennsylvania State University
503 Walker Building, University Park, PA   16802
hilton@meteo.psu.edu



More information about the NumPy-Discussion mailing list