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 9149851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:31:59+00:00 2026-06-17T11:31:59+00:00

What is the reason for this weirdness in numpy’s all ? >>> import numpy

  • 0

What is the reason for this weirdness in numpy’s all?

>>> import numpy as np
>>> np.all(xrange(10))
False
>>> np.all(i for i in xrange(10))
True
  • 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-06-17T11:32:00+00:00Added an answer on June 17, 2026 at 11:32 am

    Numpy.all does not understands generator expressions.

    From the documentation

     numpy.all(a, axis=None, out=None)
    
        Test whether all array elements along a given axis evaluate to True.
        Parameters :    
    
        a : array_like
    
            Input array or object that can be converted to an array.
    

    Ok, not very explicit, so lets look at the code

    def all(a,axis=None, out=None):
        try:
            all = a.all
        except AttributeError:
            return _wrapit(a, 'all', axis, out)
        return all(axis, out)
    
    def _wrapit(obj, method, *args, **kwds):
        try:
            wrap = obj.__array_wrap__
        except AttributeError:
            wrap = None
        result = getattr(asarray(obj),method)(*args, **kwds)
        if wrap:
            if not isinstance(result, mu.ndarray):
                result = asarray(result)
            result = wrap(result)
        return result
    

    As generator expression doesn’t have all method, it ends up calling _wrapit
    In _wrapit, it first checks for __array_wrap__ method which generates AttributeError finally ending up calling asarray on the generator expression

    From the documentation of numpy.asarray

     numpy.asarray(a, dtype=None, order=None)
    
        Convert the input to an array.
        Parameters :    
    
        a : array_like
    
            Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.
    

    It is well documented about the various types of Input data thats accepted which is definitely not generator expression

    Finally, trying

    >>> np.asarray(0 for i in range(10))
    array(<generator object <genexpr> at 0x42740828>, dtype=object)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason this script will work with all of the 'echo's at the
For some reason this C++ below keeps returning false. Any help would be apprected!
For some reason this is not working, yet all my searches say it should
For some reason this only shows the last result, instead of showing all. The
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
For some reason this line of code is giving me quite a problem. struct
For some reason this () character shows up in Firefox 10 randomly throughout my
For one or another reason this code sample gives 48 hours instead of 24,
For some reason this statement is working fine: vms.Where(vm => vm.MessageType == ValidationMessage.EnumValidationMessageType.Warning) But
For some reason this text isn't being centered. #highlightheader { background-color:#006600; color:white; font-size:30px; text-align:center;

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.