'Numpy Pick subarrays with spcific column numbers
I have created a 3D point coordinates using numpy code:
xyzlist = np.mgrid[0:m,0:m,0:m]
points = xyzlist.reshape(3,-1).T
The points results are like
[[0,0,0],[0,0,1],[0,0,2],[0,0,3],[0,1,0],[0,1,1],[0,1,2],[0,1,3],[0,2,0],[0,2,1],[0,2,2],[0,2,3],[0,3,0],[0,3,1],[0,3,2],[0,3,3]........]
How can I pick the specific points with y = 1 or 3or 5...etc.(an odd number) and z = 1 or 3 or 5...etc.(an odd number) ?
Namely the points array of [[0,1,1],[0,1,3],[0,3,1],[0,3,3]]?
Is there any simple way to do this in numpy because I have tons of points more than these?
Solution 1:[1]
Use this:
points[((points[:, 1] == 1) | (points[:, 1] == 3)) & ((points[:, 2] == 1) | (points[:, 2] == 3))]
points[:, 1] is the 2nd column, y, and points[:, 2] is the 3rd column, z.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | richardec |
