7

Why do this happen?

>>> map(numpy.all, range(-2, 3)) [-2, -1, 0, 1, 2] 

Is it intentional or is the integer just falling through a crack?

Does it have to do with:

>>> map(numpy.all, [False, True]) [False, True] 

I'm running Numpy 1.8.0.dev-74b08b3 and Python 2.7.3

6
  • 4
    I get [True, True, False, True, True], on Python 2.7.3, NumPy 1.6.1. What versions of Python and NumPy are you using? Commented May 7, 2013 at 19:02
  • 5
    I can reproduce the OP's output in 1.7.1. Commented May 7, 2013 at 19:07
  • 1
    What do you expect np.all(-2) to return? Commented May 7, 2013 at 19:07
  • 3
    This is smelling like a NumPy bug to me; using all on a scalar is an odd enough thing to do that it probably doesn't matter, but apparently zero-dimensional arrays behave this way, too: numpy.all(numpy.ones(())) gives 1.0 for me on NumPy 1.7.1. Commented May 7, 2013 at 19:24
  • 6
    github.com/numpy/numpy/issues/3314 Commented May 7, 2013 at 19:28

1 Answer 1

1

Using map(numpy.all, range(-2,3)) is actually creating a list with:

[numpy.all(-2), numpy.all(-1), numpy.all(0), numpy.all(1), numpy.all(2)] 

giving

[-2, -1, 0, 1, 2] 

If you did map(lambda x: numpy.all([x]), range(-2,3)), it would do:

[numpy.all([-2]), numpy.all([-1]), numpy.all([0]), numpy.all([1]), numpy.all([2])] 

giving

[True, True, False, True, True] 

As posted by @Mark Dickinson, there is a known issue with numpy.all in which it returns the input value instead of True or False for some inputs. In your second example map(numpy.all, [False, True]) does exactly as before, returning the input value.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.