How do i "carve" or mask a 2D numpy array according to an index formula? I don't care what the element value is, only its position in the array.
For example, given an mxm array, how do I extract all elements whose address conforms to
for i in range(0,m):
for j in range(0,m):
if j-i-k>=0:
A[i,j] = 1
elif j-p-k>=0:
A[i,j] = 1
elif i-k>=0:
A[i,j] = 1
else:
A[i,j] = 0
j=j+1
i=i+1
where
k and p are an arbitrary fences
Assume
k<m
p<m
This ends up looking like a diagonal slice + a horizontal slice + a vertical slice. Can it be done without the for loops above?