[Numpy-discussion] numpy.all docstring reality check

Skipper Seabold jsseabold at gmail.com
Tue Jun 29 22:28:03 EDT 2010


On Tue, Jun 29, 2010 at 8:50 PM, David Goldsmith
<d.l.goldsmith at 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
> copy-and-paste-from-another-docstring "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



More information about the NumPy-Discussion mailing list