[Numpy-discussion] svd headers and diagonals

dpn davidnovakovic at gmail.com
Sun May 6 08:56:17 EDT 2007


Somehow your suggestion made me think about using diag, Thanks :)

>>> mm(u,mm(numpy.diag(s),v))
matrix([[ 4.,  2.],
       [ 2.,  4.]])

Now if anyone knows how to set headers for matrices or arrays?

dpn

On 5/6/07, Matthieu Brucher <matthieu.brucher at gmail.com> wrote:
> Don't forget that '*' is element-wise for arrays, use dot instead ;)
>
> Matthieu
>
> 2007/5/6, dpn <davidnovakovic at gmail.com >:
> >
> > Hi,
> >
> > i have two questions, both loosely related to SVD.
> > I've seen this post:
> >
> http://thread.gmane.org/gmane.comp.python.numeric.general/4575
> >
> > >>> u,s,v = numpy.linalg.svd(numpy.array([[4,2],[2,4]])) # symmetric
> > matrix u == v
> > >>> u
> > array([[-0.70710678, -0.70710678],
> >        [-0.70710678,  0.70710678]])
> > >>> v
> > array([[-0.70710678, -0.70710678],
> >        [-0.70710678,  0.70710678]])
> > >>> s.shape
> > (2,)
> >
> > since my data matrix is symmetrical, i'd expect USV = X, but I don't get
> that:
> > >>> u * s * v
> > array([[ 3.,  1.],
> >        [ 3.,  1.]])
> >
> > matrixmultiply doesnt help either
> > >>> from numpy.core import matrixmultiply as mm
> > >>> mm(u,mm(s,v))
> > array([ 6.,  2.])
> >
> > Question 2.
> >
> > I'm relativly new to linealg, so i could be way off here.
> > In applications such as LSA, the dimensions of a matrix are either
> > documents or term identifiers, I noticed in PDL ( http://pdl.perl.org/
> > ), you can set the headers of row or columns.
> >
> > I havent found a way to do this in numpy, which means when the
> > dimensions get sorted by their singular value, I lose the ordering I
> > may have recorded externally.
> >
> > I there a way to store row and column headers?
> >
> > Cheers
> >
> > David Novakovic
> > _______________________________________________
> > Numpy-discussion mailing list
> > Numpy-discussion at scipy.org
> >
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>



More information about the NumPy-Discussion mailing list