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
The numpy. all() function tests whether all array elements along the mentioned axis evaluate to True. Parameters : array :[array_like]Input array or object whose elements, we need to test.
If we have a Numpy array with boolean, True or False data, we can use np. all() to check if all of the elements are True .
The default data type: float_ . The 24 built-in array scalar type objects all convert to an associated data-type object.
Can an array store different data types? Yes, a numpy array can store different data String, Integer, Complex, Float, Boolean.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With