[Numpy-discussion] conditional array indexing
Christopher Barker
Chris.Barker at noaa.gov
Mon Feb 14 18:39:00 EST 2011
On 2/14/11 2:39 PM, Bryan Woods wrote:
> Thanks for your reply. Unfortunately it is not working that simply.
>
> This tells me that "only integer arrays with one element can be
> converted to an index"
Examples, example, examples!
I think this is what you want:
In [15]: land_cover
Out[15]:
array([[4, 2, 0, 4],
[0, 2, 1, 1],
[1, 1, 4, 2]])
In [16]: z0_legend
Out[16]: array([ 3.4, 5.2, 1.3, 4.2, 6.4])
In [17]: roughness = z0_legend[land_cover]
In [18]: roughness
Out[18]:
array([[ 6.4, 1.3, 3.4, 6.4],
[ 3.4, 1.3, 5.2, 5.2],
[ 5.2, 5.2, 6.4, 1.3]])
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the NumPy-Discussion
mailing list