[Numpy-discussion] not expected output of fill_diagonal
Warren Weckesser
warren.weckesser@enthought....
Sat Jun 9 07:44:06 CDT 2012
On Fri, Jun 8, 2012 at 7:45 PM, Frédéric Bastien <nouiz@nouiz.org> wrote:
> Hi,
>
> While reviewing the Theano op that wrap numpy.fill_diagonal, we found
> an unexpected behavior of it:
>
> # as expected for square matrix
> >>> a=numpy.zeros((5,5))
> >>> numpy.fill_diagonal(a, 10)
> >>> print a
>
> # as expected long rectangular matrix
> >>> a=numpy.zeros((3,5))
> >>> numpy.fill_diagonal(a, 10)
> >>> print a
> [[ 10. 0. 0. 0. 0.]
> [ 0. 10. 0. 0. 0.]
> [ 0. 0. 10. 0. 0.]]
>
> # Not as expected
> >>> a=numpy.zeros((5,3))
> >>> numpy.fill_diagonal(a, 10)
> >>> print a
> [[ 10. 0. 0.]
> [ 0. 10. 0.]
> [ 0. 0. 10.]
> [ 0. 0. 0.]
> [ 10. 0. 0.]]
>
>
> I can make a PR that will add a parameter wrap that allow to control
> if it return the old behavior or what I would expect in the last case:
> [[ 10. 0. 0.]
> [ 0. 10. 0.]
> [ 0. 0. 10.]
> [ 0. 0. 0.]
> [ 0. 0. 0.]]
>
> My questions is, do someone else expect the current behavior? Should
> we change the default to be what I expect? Do you want that we warn if
> the user didn't specify witch behavior and in the future we change it?
>
>
There is a ticket for this:
http://projects.scipy.org/numpy/ticket/1953
I agree that the behavior is unexpected and should be fixed.
Warren
> Anything else I didn't think?
>
> thanks
>
> Fred
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120609/8f974e84/attachment.html
More information about the NumPy-Discussion
mailing list