numpy.all docstring reality check
Hi, folks. Under Parameters, the docstring for numpy.core.fromnumeric.all says:
"out : ndarray, optionalAlternative output array in which to place the result. It must have the same shape as the expected output and *the type is preserved*." [emphasis added].I assume this is a copyandpastefromanotherdocstring "typo" (shouldn't it be (possibly ndarray of) bool), but I just wanted to double check.
DG
On Tue, Jun 29, 2010 at 8:50 PM, David Goldsmith d.l.goldsmith@gmail.com wrote:
Hi, folks. Under Parameters, the docstring for numpy.core.fromnumeric.all says:
"out : ndarray, optionalAlternative output array in which to place the result. It must have the same shape as the expected output and the type is preserved." [emphasis added].I assume this is a copyandpastefromanotherdocstring "typo" (shouldn't it be (possibly ndarray of) bool), but I just wanted to double check.
Looks right to me though there is no
In [255]: a = np.ones(10)
In [256]: b = np.empty(1,dtype=int)
In [257]: np.core.fromnumeric.all(a,out=b) Out[257]: array([1])
In [258]: b.dtype Out[258]: dtype('int64')
In [259]: b = np.empty(1,dtype=bool)
In [260]: np.core.fromnumeric.all(a,out=b) Out[260]: array([ True], dtype=bool)
In [261]: b.dtype Out[261]: dtype('bool')
In [262]: b = np.empty(1)
In [263]: np.core.fromnumeric.all(a,out=b) Out[263]: array([ 1.])
In [264]: b.dtype Out[264]: dtype('float64')
In [265]: a2 = np.column_stack((np.ones(10),np.ones(10),np.random.randint(0,2,10)))
In [266]: b = np.empty(3,dtype=int)
In [267]: np.core.fromnumeric.all(a2,axis=0,out=b) Out[267]: array([1, 1, 0])
In [268]: b.dtype Out[268]: dtype('int64')
This is interesting
In [300]: b = np.ones(3,dtype='a3')
In [301]: np.core.fromnumeric.all(a2,axis=0,out=b) Out[301]: array(['Tru', 'Tru', 'Fal'], dtype='S3')
Skipper
OK, now I understand: dtype(out) is preserved, whatever that happens to be, not dtype(a) (which is what I thought it meant)  I better clarify. Thanks!
DG
On Tue, Jun 29, 2010 at 7:28 PM, Skipper Seabold jsseabold@gmail.comwrote:
On Tue, Jun 29, 2010 at 8:50 PM, David Goldsmith d.l.goldsmith@gmail.com wrote:
Hi, folks. Under Parameters, the docstring for
numpy.core.fromnumeric.all
says:
"out : ndarray, optionalAlternative output array in which to place the result. It must have the same shape as the expected output and the type
is
preserved." [emphasis added].I assume this is a copyandpastefromanotherdocstring "typo" (shouldn't it be (possibly ndarray of) bool), but I just wanted to double check.
Looks right to me though there is no
In [255]: a = np.ones(10)
In [256]: b = np.empty(1,dtype=int)
In [257]: np.core.fromnumeric.all(a,out=b) Out[257]: array([1])
In [258]: b.dtype Out[258]: dtype('int64')
In [259]: b = np.empty(1,dtype=bool)
In [260]: np.core.fromnumeric.all(a,out=b) Out[260]: array([ True], dtype=bool)
In [261]: b.dtype Out[261]: dtype('bool')
In [262]: b = np.empty(1)
In [263]: np.core.fromnumeric.all(a,out=b) Out[263]: array([ 1.])
In [264]: b.dtype Out[264]: dtype('float64')
In [265]: a2 = np.column_stack((np.ones(10),np.ones(10),np.random.randint(0,2,10)))
In [266]: b = np.empty(3,dtype=int)
In [267]: np.core.fromnumeric.all(a2,axis=0,out=b) Out[267]: array([1, 1, 0])
In [268]: b.dtype Out[268]: dtype('int64')
This is interesting
In [300]: b = np.ones(3,dtype='a3')
In [301]: np.core.fromnumeric.all(a2,axis=0,out=b) Out[301]: array(['Tru', 'Tru', 'Fal'], dtype='S3')
Skipper _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
This behavior is quite curious. While it is consistent and it behaves exactly as documented (after clarification), I am curious about the rational. Is it merely an unavoidable consequence of passing in the output array?
Certainly a few examples from the above emails would make this extremely clear. I particularly liked the 'a3' dtype example.
Ben Root
On Tue, Jun 29, 2010 at 9:38 PM, David Goldsmith d.l.goldsmith@gmail.comwrote:
OK, now I understand: dtype(out) is preserved, whatever that happens to be, not dtype(a) (which is what I thought it meant)  I better clarify. Thanks!
DG
On Tue, Jun 29, 2010 at 7:28 PM, Skipper Seabold jsseabold@gmail.comwrote:
On Tue, Jun 29, 2010 at 8:50 PM, David Goldsmith d.l.goldsmith@gmail.com wrote:
Hi, folks. Under Parameters, the docstring for
numpy.core.fromnumeric.all
says:
"out : ndarray, optionalAlternative output array in which to place the result. It must have the same shape as the expected output and the type
is
preserved." [emphasis added].I assume this is a copyandpastefromanotherdocstring "typo" (shouldn't it be (possibly ndarray of) bool), but I just wanted to double check.
Looks right to me though there is no
In [255]: a = np.ones(10)
In [256]: b = np.empty(1,dtype=int)
In [257]: np.core.fromnumeric.all(a,out=b) Out[257]: array([1])
In [258]: b.dtype Out[258]: dtype('int64')
In [259]: b = np.empty(1,dtype=bool)
In [260]: np.core.fromnumeric.all(a,out=b) Out[260]: array([ True], dtype=bool)
In [261]: b.dtype Out[261]: dtype('bool')
In [262]: b = np.empty(1)
In [263]: np.core.fromnumeric.all(a,out=b) Out[263]: array([ 1.])
In [264]: b.dtype Out[264]: dtype('float64')
In [265]: a2 = np.column_stack((np.ones(10),np.ones(10),np.random.randint(0,2,10)))
In [266]: b = np.empty(3,dtype=int)
In [267]: np.core.fromnumeric.all(a2,axis=0,out=b) Out[267]: array([1, 1, 0])
In [268]: b.dtype Out[268]: dtype('int64')
This is interesting
In [300]: b = np.ones(3,dtype='a3')
In [301]: np.core.fromnumeric.all(a2,axis=0,out=b) Out[301]: array(['Tru', 'Tru', 'Fal'], dtype='S3')
Skipper _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
 Mathematician: noun, someone who disavows certainty when their uncertainty set is nonempty, even if that set has measure zero.
Hope: noun, that delusive spirit which escaped Pandora's jar and, with her lies, prevents mankind from committing a general suicide. (As interpreted by Robert Graves)
NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
participants (3)

Benjamin Root

David Goldsmith

Skipper Seabold