
Perhaps I do not understand something properly, if so could someone please explain the behavior I notice with numpy.linalg.svd when acting on arrays. It gives the incorrect answer, but works fine with matrices. My numpy is 1.1.0.
R = n.array([[3.6,.35],[.35,1.8]]) V,D,W = n.linalg.svd(R) V*n.diag(D)*W.transpose() array([[ 3.5410365 , 0. ], [ 0. , 1.67537611]]) R = n.matrix([[3.6,.35],[.35,1.8]]) V,D,W = n.linalg.svd(R) V*n.diag(D)*W.transpose() matrix([[ 3.6 , 0.35], [ 0.35, 1.8 ]])
Thanks in advance, Frank -- Frank Lagor Ph.D. Candidate Mechanical Engineering and Applied Mechanics University of Pennsylvania

On Fri, Jul 25, 2008 at 12:32 PM, Frank Lagor <dfranci@seas.upenn.edu> wrote:
Perhaps I do not understand something properly, if so could someone please explain the behavior I notice with numpy.linalg.svd when acting on arrays. It gives the incorrect answer, but works fine with matrices. My numpy is 1.1.0.
R = n.array([[3.6,.35],[.35,1.8]]) V,D,W = n.linalg.svd(R) V*n.diag(D)*W.transpose() array([[ 3.5410365 , 0. ], [ 0. , 1.67537611]]) R = n.matrix([[3.6,.35],[.35,1.8]]) V,D,W = n.linalg.svd(R) V*n.diag(D)*W.transpose() matrix([[ 3.6 , 0.35], [ 0.35, 1.8 ]])
'*' does element-by-element multiplication for arrays but matrix multiplication for matrices.

On Fri, Jul 25, 2008 at 12:36 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
On Fri, Jul 25, 2008 at 12:32 PM, Frank Lagor <dfranci@seas.upenn.edu> wrote:
Perhaps I do not understand something properly, if so could someone please explain the behavior I notice with numpy.linalg.svd when acting on arrays. It gives the incorrect answer, but works fine with matrices. My numpy is 1.1.0.
R = n.array([[3.6,.35],[.35,1.8]]) V,D,W = n.linalg.svd(R) V*n.diag(D)*W.transpose() array([[ 3.5410365 , 0. ], [ 0. , 1.67537611]]) R = n.matrix([[3.6,.35],[.35,1.8]]) V,D,W = n.linalg.svd(R) V*n.diag(D)*W.transpose() matrix([[ 3.6 , 0.35], [ 0.35, 1.8 ]])
'*' does element-by-element multiplication for arrays but matrix multiplication for matrices.
As a check (for the array case):
n.dot(V, n.dot(n.diag(D), W.transpose())) # That's hard to read!
array([[ 3.6 , 0.35], [ 0.35, 1.8 ]])

On Fri, Jul 25, 2008 at 9:39 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
On Fri, Jul 25, 2008 at 12:32 PM, Frank Lagor <dfranci@seas.upenn.edu> wrote:
Perhaps I do not understand something properly, if so could someone
On Fri, Jul 25, 2008 at 12:36 PM, Keith Goodman <kwgoodman@gmail.com> wrote: please
explain the behavior I notice with numpy.linalg.svd when acting on arrays. It gives the incorrect answer, but works fine with matrices. My numpy is
'*' does element-by-element multiplication for arrays but matrix multiplication for mat
n.dot(V, n.dot(n.diag(D), W.transpose())) # That's hard to read!
Just two small points: 1.) Broadcasting may be easier on the eye ... well, atleast when you have gotten used to it Then the above is np.dot(V*D, W) 2.) Also, note that the right hand side eigenvectors in numpy's svd routine is ordered by rows! Yes, I know this is confusing as it is different from just about any other linear algebra software out there, but the documentation is clear. It is also a little inconsistent with eig and eigh, some more experienced user can probably answer on why it is like that? Arnar
<http://projects.scipy.org/mailman/listinfo/numpy-discussion>

On Fri, Jul 25, 2008 at 14:32, Frank Lagor <dfranci@seas.upenn.edu> wrote:
Perhaps I do not understand something properly, if so could someone please explain the behavior I notice with numpy.linalg.svd when acting on arrays. It gives the incorrect answer, but works fine with matrices. My numpy is 1.1.0.
R = n.array([[3.6,.35],[.35,1.8]]) V,D,W = n.linalg.svd(R) V*n.diag(D)*W.transpose()
For regular arrays, * is element-wise multiplication, not matrix multiplication. For matrix objects, * is matrix multiplication. -- Robert Kern "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
participants (4)
-
Arnar Flatberg
-
Frank Lagor
-
Keith Goodman
-
Robert Kern