Home > Mobile >  How to zip operations on nummpy arrays where conditional filter needs to be applied only on one of t
How to zip operations on nummpy arrays where conditional filter needs to be applied only on one of t

Time:10-05

I have a 2d nummpy array something like this:

(array([[7.948829 , 3.7127783, 3.6365926, 3.4607997]], dtype=float32),
 array([[ 5, 15,  7, 39]]))

The first array in this array are distances and the second is indices, I want to know if there is a way I could filter the first array based on a certain threshold and then also delete the corresponding indices from the index?

CodePudding user response:

you mean like this?

import numpy as np
a = np.array([7.948829 , 3.7127783, 3.6365926, 3.4607997])
b = np.array([ 5, 15,  7, 39])
c = b[a>3.7]
d = a[a>3.7]
print(f'c = \n{c}')
print(f'd = \n{d}')

output:

c = 
[ 5 15]
d = 
[7.948829  3.7127783]
  • Related