don't understand matrix-multiplication should be reversed in python?

PythonDude mjoerg.phone at gmail.com
Fri Nov 13 03:56:03 EST 2015


On Thursday, 12 November 2015 17:35:39 UTC+1, Ian  wrote:
> On Thu, Nov 12, 2015 at 8:57 AM, PythonDude <xxx....com> wrote:
> > Hi all,
> > Anyone could please explain or elaborate on exactly this (quote): "Keep in mind that Python has a reversed definition of rows and columns"???
> >
> > That I don't understand - thank you for any hints/guidance/explanations/ideas/suggestions etc!
> 
> py> import numpy
> py> p = numpy.reshape(range(5), (5,1))
> py> p
> array([[0],
>        [1],
>        [2],
>        [3],
>        [4]])
> py> p.T
> array([[0, 1, 2, 3, 4]])
> py> p.dot(p.T)
> array([[ 0,  0,  0,  0,  0],
>        [ 0,  1,  2,  3,  4],
>        [ 0,  2,  4,  6,  8],
>        [ 0,  3,  6,  9, 12],
>        [ 0,  4,  8, 12, 16]])
> py> p.T.dot(p)
> array([[30]])
> py> m = numpy.asmatrix(p)
> py> m
> matrix([[0],
>         [1],
>         [2],
>         [3],
>         [4]])
> py> m.T
> matrix([[0, 1, 2, 3, 4]])
> py> m * m.T
> matrix([[ 0,  0,  0,  0,  0],
>         [ 0,  1,  2,  3,  4],
>         [ 0,  2,  4,  6,  8],
>         [ 0,  3,  6,  9, 12],
>         [ 0,  4,  8, 12, 16]])
> py> m.T * m
> matrix([[30]])
> 
> Yeah, I don't know what that person is talking about either. It looks
> correct to me.

Thank you very much, Ian - just had to be sure about this - I would also be very disappointed in Python, if this author was right about this non-intuitive interpretation of how to do matrix multiplication :-)



More information about the Python-list mailing list