One question about mask 2-d np.array data.
For example:
- one 2-d np.array
valuein the shape of 20 x 20. - An index
t = [(1,2),(3,4),(5,7),(12,13)]
How to mask the 2-d array value by the (y,x) in index?
Usually, replacing with np.nan are based on the specific value like y[y==7] = np.nan
On my example, I want to replace the value specific location with np.nan.
For now, I can do it by:
- Creating a new array
value_maskin the shape of 20 x 20 - Loop the
valueand testify the location by (i,j) == t[k] - If True,
value_mask[i,j]=value[i,j]; In verse,value_mask[i,j]= np.nan
My method was too bulky especially for hugh data(3 levels of loops).
Are there some efficiency method to achieve that? Any advice would be appreciate.