Numpy select rows based on condition
Use a boolean mask:
mask = (z[:, 0] == 6)
z[mask, :]
This is much more efficient than np.where
because you can use the boolean mask directly, without having the overhead of converting it to an array of indices first.
One liner:
z[z[:, 0] == 6, :]
Program:
import numpy as np
np_array = np.array([[0,4],[0,5],[3,5],[6,8],[9,1],[6,1]])
rows=np.where(np_array[:,0]==6)
print(np_array[rows])
Output:
[[6 8]
[6 1]]
And If You Want to Get Into 2d List use
np_array[rows].tolist()
Output of 2d List
[[6, 8], [6, 1]]