[Numpy-discussion] Is this a bug?
Timothy Hochberg
tim.hochberg@ieee....
Sun Sep 16 15:02:23 CDT 2007
On 9/16/07, Charles R Harris <charlesr.harris@gmail.com> wrote:
>
> I note a small inconsistency in the use of the out keyword in some
> functions:
>
> >>> a=array(0)
> >>> sometrue([1],out=a).shape
> ()
> >>> a=array([0])
> >>> sometrue([1],out=a).shape
> (1,)
> >>> a=array([[0]])
> >>> sometrue([1],out=a).shape
> (1, 1)
> >>> a=array([[0,0]])
> >>> sometrue(eye(2),axis=1,out=a).shape
> (1, 2)
>
> It seems to me that all but the first case should raise an error, as the
> shape of the output array is not the same as the expected output. I know
> this looks picky, but 0d arrays can't be indexed, whereas 1d and 2d arrays
> can, so they aren't quite compatible. Besides, the current behavior is
> difficult to describe for the documentation. If the current behavior is the
> rule, what is that rule?
I'm not sure what the rule is. FWIW, *a* rule that fits the behavior
described above and is pretty easy to explain is:
FUNC(..., out=a) <=> a[...] = FUNC(...)
To work with the above example:
>>> a = array(0)
>>> a[...] = sometrue([1])
>>> a
array(1)
>>> a = array([0])
>>> a[...] = sometrue([1])
>>> a
array([1])
>>> a = array([[0]])
>>> a[...] = sometrue([1])
>>> a
array([[1]])
>>> a = array([[0,0]])
>>> a[...] = sometrue([1])
>>> a
array([[1, 1]])
I'm not sure if other functions are consistent with this rule, however. Nor
have I thought it through enough to convince myself that this is the best
rule there is, although at first glance it seems fairly reasonable.
Chuck
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
--
. __
. |-\
.
. tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070916/b2e8edc0/attachment.html
More information about the Numpy-discussion
mailing list