I would like to remove elements from one array B
that have the same index as the inf
elements from another array A
.
I have two numpy array such as
A = np.array([1,2,3,4, float('inf')])
B = np.array([5, 6, 7, 8, 9])
If I do B[A>2]
, the output is array([7, 8, 9])
. However, if I do B[math.isfinite(A)]
, then I get an error
TypeError: only size-1 arrays can be converted to Python scalars
How can I select the elements from B
where the value in A
is not infinity?