1

I have a array of numpy arrays

[array([5, 5, 5]), array([6, 6, 6])]

However if I try to check if an object exists in that array

[5, 5, 5] in x

I get this error

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Is there any way to fix this? Or am I doing something wrong?

1
  • First let's be clear, is x a list or ndarray? If ndarray how did you create it? You get the ambiguity error because in is using an equality test, and an_array==something produces a boolean array, many true/false values. alist==another_list produces a simple True/False. That's not the case with arrays. So in general in is a poor test when working with arrays. Commented Feb 1, 2020 at 19:46

1 Answer 1

2

You are check to see if a list exists in an array of arrays. Convert your list to an array and it should work.

>>> x=np.array([np.array([5, 5, 5]), np.array([6, 6, 6])])
>>> np.array([5, 5, 5]) in x
True
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.