[Numpy-discussion] Re: linalg.svd returns fortran arrays, causes problems
Zachary Pincus
zpincus at stanford.edu
Mon Mar 20 17:18:15 CST 2006
> Can you give us some small, self-contained code that demonstrates
> the problem?
u, s, vt = numpy.linalg.svd([[1,2],[3,4]])
u.flags.fortran
True
The problem, as per my original email, is that linalg.svd seems to be
now returning fortran-style arrays. I believe that it did not do this
in the past, but I am not certain.
It is also possible that linalg.svd always returned fortran arrays,
and the behavior of numpy.reshape with regard to fortran arrays has
changed. Here is an example of how numpy.reshape differs with fortran
and c-style arrays. I do not know if this is a bug, or the desired
behavior.
numpy.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])
array([[[ 1, 2],
[ 3, 4],
[ 5, 6],
[ 7, 8],
[ 9, 10]],
[[11, 12],
[13, 14],
[15, 16],
[17, 18],
[19, 20]]])
numpy.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])
array([[[ 1, 6],
[ 2, 7],
[ 3, 8],
[ 4, 9],
[ 5, 10]],
[[11, 16],
[12, 17],
[13, 18],
[14, 19],
[15, 20]]])
In any case, there are two issues at play:
(1) Should any numpy functions be allowed to return fortran arrays
unless specifically requested?
(2) Should all structural operations like reshape (etc.) behave the
same for fortran and c-style arrays?
If 2 can be guaranteed, then (1) doesn't really matter, I think. But
I'm not sure if 2 should be guaranteed or not.
> And what version of numpy *did* work for you?
I do not recall, unfortunately. It was a svn checkout not more than
two weeks old. Again, what I'm reporting isn't *necessarily* a bug,
but at least one (if not two) changes in semantics which are at least
problematic, and at most a bug.
Zach
On Mar 20, 2006, at 4:45 PM, Robert Kern wrote:
> Zachary Pincus wrote:
>> Hi folks,
>>
>> I recently updated to the SVN head of numpy, and most of my data
>> analysis code broke! Specifically, this code involved computing
>> the SVD
>> of flattened multidimensional data, and then reshaping the
>> results back
>> to the correct dimensionality. (A very common operation.) Now these
>> reshape operations don't generate the right results.
>
> Can you give us some small, self-contained code that demonstrates
> the problem?
>
> --
> 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
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> that extends applications into web and mobile media. Attend the
> live webcast
> and join the prime developer group breaking into this new coding
> territory!
> http://sel.as-us.falkag.net/sel?
> cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
More information about the Numpy-discussion
mailing list