python - numpy boolean indexing multiple conditions -


i have 2 dimensional numpy array , using python 3.5. starting learn boolean indexing way cool. can 2 dimensional array, arr. mask = arr > 127 arr[mask] = 0

this works perfect trying change logic use boolean indexing

for x in range(arr.shape[0]):     y in range(arr.shape[1]):         if arr[x,y] < -10:             arr[x,y] = 0         elif arr[x,y] < 15:             arr[x,y] = arr[x,y] + 5         else:             arr[x,y] = 30 

i tried multiple conditional operators indexing following error:

valueerror: boolean index array should have 1 dimension boolean index array should have 1 dimension.

i tried multiple versions try work. here 1 try produced valueerror.

 arr_temp = arr.copy()  mask = arry_temp < -10  mask2 = arry_temp < 15  mask3 = mask ^ mask3  arr[mask] = 0  arr[mask3] = arry[mask3] + 5  arry[~mask2] = 30  

i received error on mask3. new know code above not efficient trying work out it.

any tips appreciated.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -