[SciPy-User] A newbie question on matrix multiplication

Ivo Maljevic ivo.maljevic at gmail.com
Thu Mar 25 10:13:05 EDT 2010


You may find that, and some other useful tips here:

http://www.scipy.org/NumPy_for_Matlab_Users



On 25 March 2010 09:49, Graziano Mirata <graziano.mirata at lu.unisi.ch> wrote:

> Great! Thanx
>
> On Mar 25, 2010, at 2:41 PM, Angus McMorland wrote:
>
> > On 25 March 2010 09:29, Graziano Mirata <graziano.mirata at lu.unisi.ch>
> wrote:
> >> Hi to everybody,
> >> i am new here and above all I am new in python. After years of matlab
> >> programming I finally have switched to Python.
> >>
> >> Coming to question: i am trying to multiply a matrix transpose by itself
> but
> >> i've got an error on the shape. But it is impossible. Here there is the
> >> code:
> >>
> >> type(f)
> >> Out[213]: <type 'numpy.ndarray'>
> >>
> >> In [214]: type(ft)
> >> Out[214]: <type 'numpy.ndarray'>
> >>
> >> In [215]: f.size
> >> Out[215]: 12
> >>
> >> In [216]: f.shape
> >> Out[216]: (4, 3)
> >>
> >> In [217]: ft = f.transpose()
> >>
> >> In [218]: ft.shape
> >> Out[218]: (3, 4)
> >>
> >> In [219]: ft*f
> >
> > In python the * operator isn't overloaded to mean matrix
> > multiplication, meaning that ft * f tries to do element-wise
> > multiplication, and (3,4) * (4,3) aren't compatible shapes for that.
> > Try np.dot(ft, f) instead.
> >
> > Angus.
> > --
> > AJC McMorland
> > Post-doctoral research fellow
> > Neurobiology, University of Pittsburgh
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User at scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100325/ad0ca053/attachment.html>


More information about the SciPy-User mailing list