Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:02:47+00:00 2026-05-26T14:02:47+00:00

I would appreciate if somebody could help me with this (and explaining what’s going

  • 0

I would appreciate if somebody could help me with this (and explaining what’s going on).

This works:

>>> from numpy import array
>>> a = array((2, 1))
>>> b = array((3, 3))
>>> l = [a, b]
>>> a in l
True

But this does not:

>>> c = array((2, 1))
>>> c in l
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The behaviour I would like to replicate is:

>>> x = (2, 1)
>>> y = (3, 3)
>>> l2 = [x, y]
>>> z = (2, 1)
>>> z in l2
True

Note that what above also work with mutable objects:

>>> x = [2, 1]
>>> y = [3, 3]
>>> l2 = [x, y]
>>> z = [2, 1]
>>> z in l2
True

Of course, knowing that:

>>> (a < b).all()
True

I tried (and failed):

>>> (c in l).all()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:02:47+00:00Added an answer on May 26, 2026 at 2:02 pm

    Python makes the choice that bool([False,True]) is True because (it says) any non-empy list has boolean value True.

    Numpy makes the choice that bool(np.array([False, True])) should raise a ValueError. Numpy was designed from the point of view that some users may want to know if any of the elements in the array are True, while others may want to know if all the elements in the array are True. Since the users may have conflicting desires, NumPy refuses to guess. It raises a ValueError and suggests using np.any or np.all (though if one wishes to replicate Python-like behavior, you’d use len).

    When you evaluate c in l, Python compares c with each element in l starting with a. It evaluates bool(c==a). We get bool(np.array([True True])), which raises a ValueError (for the reason described above).

    Since numpy refuses to guess, you have to be specific. I suggest:

    import numpy as np
    a=np.array((2,1))
    b=np.array((3,3))
    c=np.array((2,1))
    l=[a,b]
    print(any(np.all(c==elt) for elt in l))
    # True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would appreciate if somebody could help me with something like this: NOTE!: I Do
As always, I would appreciate very much if somebody out there could help me
I would really appreciate if somebody could tell me why compilation of this program:
I would appreciate any help on this issue. Lets say I want to load
That's an odd title. I would greatly appreciate it if somebody could clarify what
I was hoping somebody could help me with with this. I am trying to
I would appreciate it if somebody could tell me how to bind a listbox
I would appreciate some help with something I working on and have not done
I would appreciate some help with an UPDATE statement. I want to update tblOrderHead
I'm new to regular expressions and would appreciate your help. I'm trying to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.