I have a 1D array:
arr = np.array([0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 2, 0, 0, 0, 0, 0, 2, 3, 0, 0, 1, ...], dtype='uint16')
I want to create a mask array that is True anywhere that is +/- N indexes of of a value greater than 2, yielding the following (for N=3)
mask = [F, T, T, T, T, T, T, T, F, F, T, T, T, T, T, T, T, F, F, F, T, T, T, T, T, T, T, ...]
(note, I used T/F for readability's sake)
I need this to be rather fast as my actual array is millions of points long, N will likely be something like 500.
Edit: similar problem
arr = [0, 0, ...]is not an array but a list. Did you mean a list or it is really a Numpy array? If so, what is itsdtype?ndarraywithdtype=uint16np.convolve(arr>2, np.full(2*N+1, True), "same")?