[Numpy-discussion] not expected output of fill_diagonal

Frédéric Bastien nouiz@nouiz....
Mon Jun 11 15:45:54 CDT 2012


Thanks,

I made a PR to fix it. I changed the current behavior to don't "wrap",
but there is an option to change it. If someone think that we should
not change the current default behavior. tell me.

https://github.com/numpy/numpy/pull/306

Fred

On Sat, Jun 9, 2012 at 8:44 AM, Warren Weckesser
<warren.weckesser@enthought.com> wrote:
>
>
> 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
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list