[Numpy-discussion] conditional array indexing

Bryan Woods bwoods at aer.com
Mon Feb 14 17:21:07 EST 2011


I have spent over an hour now trying to figure out what I thought would 
be a really basic conditional array assignment. I am very new to python 
and am in need of help.

I have a 2D integer array of land cover classes and a 1D array with a 
roughness value for each class. I am trying to create a new 2D array 
containing a map of the roughness values.

I am trying the following code:

roughness = np.array(landcover.shape,dtype='f')
for i in range(np.min(landcover),np.max(landcover)):
     roughness[landcover == i] = z0_legend[i]

Alas it tells me that I can only have a 1D boolean array index. What is 
the easiest way around this without having to loop through each row of 
the 2D array. I need to keep this vectorized as much as possible as 
these arrays are very large.

Thanks,
Bryan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bwoods.vcf
Type: text/x-vcard
Size: 341 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110214/09576058/attachment.vcf>


More information about the NumPy-Discussion mailing list