I have an array
a = np.array([[1, 2.0, 3],
[1.23,2.5,3],
[1,4.6,4.9]])
I want to check each value in the 2nd column for a whole number and keep that row if it is a whole number. I have tried this.
for i in range(0,len(a)):
try:
if a[i,1].is_integer()==False:
a=np.delete(a,(i),axis=0)
except IndexError:
continue
Output:
array([[1. , 2. , 3. ],
[1. , 4.6, 4.9]])
Desired output: array([[1. , 2. , 3. ]])
Reason for failure: When a row is deleted, i
the row below moves up. Getting the desired output without using delete
is also okay.
output = a[np.mod(a[:, 1], 1) == 0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With