[Numpy-discussion] not expected output of fill_diagonal
Frédéric Bastien
nouiz@nouiz....
Fri Jun 8 19:45:17 CDT 2012
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?
Anything else I didn't think?
thanks
Fred
More information about the NumPy-Discussion
mailing list