numpy 2d where with constraint on each row
I have a numpy array of shape (2,N) and three constraints to filter on. No value in a column may be negative Row 0 must be less than a constant, say xmax Row 1 must be less than a constant, say ymax Here is what I've tried: xmax, ymax = 7, 8 dst = np.linspace(-2,10,20).reshape((2,-1)).astype(np.int32) mask = np.where((0 <= dst) & (dst[1,:] < xmax) & (dst[0,:] < ymax)) mask = np.vstack(mask).T for p in mask: print(p, dst[:,p[1]]) Which produces (array([[-2, -1, 0, 0, 0, 1, 1, 2, 3, 3], [ 4, 4, 5, 6, 6, 7, 8, 8, 9, 10]]), (2L, 10L)) (array([0, 2]), array([0, 5])) (array([0, 3]), array([0, 6])) (
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.