2

I have a array

z = np.random.random((10,10))  --> two dimensions

with a mask

y,x=np.mgrid[slice(0,61, 1),slice(0,106, 1)] 

sorted = np.sort(z,axis=None)
mask = ma.masked_inside(z,sorted[10],sorted[-10])

mask is Array masked inside only the 10 min element and 10 max inside with a mask TRUE. I need the index position to put x,y in the annotate, but only like create element that is masked

I will like return mask elements masked and the index position in the axis of all the elements to create a automatic annotates objects

 ax.annotate(str(j)+" Altura",xy=(i,j))

1 Answer 1

3

To return the "index position", use np.where on the mask. For example:

import numpy as np
A = np.array([[2,7,9],[9,1,4],[8,7,2]])
idx = A<3 # The mask

print np.where(idx)
print zip(*np.where(idx))

Gives:

(array([0, 1, 2]), array([0, 1, 2]))
[(0, 0), (1, 1), (2, 2)]

that is, the locations where A<3. I find zipping over the elements and packaging them as a list of tuples useful, but use the first representation to index them back from the original array.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. And if I have the array masked in this moment. this is my final array masked _f_data= np.ma.masked_array(np.around(z, decimals=4, out=None),~_c)
@virtualsets I'm not sure I understand what you're asking in that comment.
I not understand your mask, my mask is ~c and is the joint of two another mask. I have one mask ~c and one array z

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.