On 9/16/07, Charles R Harris <[EMAIL PROTECTED]> 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 > [email protected] > http://projects.scipy.org/mailman/listinfo/numpy-discussion > > -- . __ . |-\ . . [EMAIL PROTECTED]
_______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
