Issue 26596: numpy.all np.all .all (original) (raw)

Issue26596

Created on 2016-03-20 23:33 by JoseLight, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Screen Shot 2016-03-20 at 4.33.22 PM.png JoseLight,2016-03-20 23:33
Messages (3)
msg262093 - (view) Author: Jose (JoseLight) Date: 2016-03-20 23:33
the numpy.all function does not work. I created A = np.random.random((10,1)) np.all(A)<1 gives me False, which is wrong! and B = 2 * A np.all(B)<2 gives me True, which is correct! also np.sum(A) < 10, gives me True, which is correct!
msg262094 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-03-21 00:06
NumPy is not part of Python's standard library, so this is a 3rd party problem. However, please don't waste the time of the NumPy developers with this. You either haven't read the documentation or have misread it. numpy.all [1] is an AND reduction over the specified dimension or all dimensions of an array. >>> import numpy as np >>> A = np.random.random((10, 1)) >>> np.all(A) True >>> True < 1 False >>> isinstance(True, int) True >>> int(True) 1 The following checks whether all values are less than 1: >>> A < 1 array([[ True], [ True], [ True], [ True], [ True], [ True], [ True], [ True], [ True], [ True]], dtype=bool) >>> np.all(A < 1) True [1]: http://docs.scipy.org/doc/numpy/reference/generated/numpy.all.html
msg262095 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-03-21 00:10
This is not a bug, but behaving correctly. You have: py> A = np.random.random((10,1)) py> np.all(A) True py> np.all(A) < 1 # is True less than 1? False which is correct: True is *not* less than 1. But True *is* less than 2: py> True < 2 True py> np.all(2*A) True Also, for future reference, please do not post screen shoots unless you absolutely have to. Screenshots make it impossible to copy the code from your example, and make it difficult for anyone who is visually impaired and using a screen-reader to contribute. Instead, copy and paste the text from your interpreter. Thank you.
History
Date User Action Args
2022-04-11 14:58:28 admin set github: 70783
2016-03-21 00:10:41 steven.daprano set nosy: + steven.dapranomessages: +
2016-03-21 00:06:33 eryksun set status: open -> closednosy: + eryksunmessages: + resolution: third partystage: resolved
2016-03-20 23:33:48 JoseLight create