0

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?

4
  • Does this answer your question? Commented Feb 3, 2020 at 10:52
  • I am using numpy arrays, not pandas dataframes. The methods aren't quite the same Commented Feb 3, 2020 at 10:53
  • Also, I the question isn't about dropping infs from A, but rather about dropping elements in B that are in the same position as infs from A. Commented Feb 3, 2020 at 10:54
  • math.Isfinite() doesn't work with array as an arguments Commented Feb 3, 2020 at 11:05

1 Answer 1

2

I think you have the answer in your question:

B = B[A!= float('inf')]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.