[Numpy-discussion] Re: linalg.svd returns fortran arrays, causes problems

Robert Kern robert.kern at gmail.com
Mon Mar 20 20:13:22 CST 2006


Travis Oliphant wrote:
> Robert Kern wrote:
> 
>> I think this is a new bug, then.
>>
>> In [82]: reshape(numpy.array([[1,2,3,4,5,6,7,8,9,10],
>> [11,12,13,14,15,16,17,18,19,20]], fortran = True), (2,5,2))
>> Out[82]:
>> array([[[ 1,  2],
>>         [ 3,  4],
>>         [ 5,  6],
>>         [ 7,  8],
>>         [ 9, 10]],
>>
>>        [[11, 12],
>>         [13, 14],
>>         [15, 16],
>>         [17, 18],
>>         [19, 20]]])
>>
>> In [83]: reshape(numpy.array([[1,2,3,4,5,6,7,8,9,10],
>> [11,12,13,14,15,16,17,18,19,20]], fortran = False), (2,5,2))
>> Out[83]:
>> array([[[ 1,  2],
>>         [ 3,  4],
>>         [ 5,  6],
>>         [ 7,  8],
>>         [ 9, 10]],
>>
>>        [[11, 12],
>>         [13, 14],
>>         [15, 16],
>>         [17, 18],
>>         [19, 20]]])   
> 
> Robert,  can you test
> 
> numpy.array([[1,2,3,4,5,6,7,8,9,10],[11,12,13,14,15,16,17,18,19,20]],
> fortran = False).reshape(2,5,2)
> 
> numpy.array([[1,2,3,4,5,6,7,8,9,10],[11,12,13,14,15,16,17,18,19,20]],
> fortran = False).reshape(2,5,2)
> 
> please?
> 
> The reshape method has not changed since your version, but the reshape
> wrapper did change slightly, I believe.  In a manner that could have
> caused this difference.

Huh. *That* displays the bug.

In [85]: numpy.array([[1,2,3,4,5,6,7,8,9,10], [11,12,13,14,15,16,17,18,19,20]],
fortran=False).reshape(2,5,2)
Out[85]:
array([[[ 1,  2],
        [ 3,  4],
        [ 5,  6],
        [ 7,  8],
        [ 9, 10]],

       [[11, 12],
        [13, 14],
        [15, 16],
        [17, 18],
        [19, 20]]])

In [86]: numpy.array([[1,2,3,4,5,6,7,8,9,10], [11,12,13,14,15,16,17,18,19,20]],
fortran=True).reshape(2,5,2)
Out[86]:
array([[[ 1,  6],
        [ 2,  7],
        [ 3,  8],
        [ 4,  9],
        [ 5, 10]],

       [[11, 16],
        [12, 17],
        [13, 18],
        [14, 19],
        [15, 20]]])


-- 
Robert Kern
robert.kern at gmail.com

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco





More information about the Numpy-discussion mailing list