# [SciPy-User] matrix multiplication

Sturla Molden sturla@molden...
Fri Jan 20 21:48:30 CST 2012

```Den 20. jan. 2012 kl. 21:03 skrev Chris Lirakis <clirakis@gmail.com>:

> I have tried the following and they all yield the same result.
>
> A = zeros(3,1)
> B = A * A.T
> B = [[ 0 0 0]
>        [0 0 0]
>        [0  0 0]]

This is due to NumPy's array broadcasting rules (arrays are not matrices). Fortran 90 would do this as well, MATLAB would not (.* does not broadcast).

Use np.dot for vector dot product and matrix multiplication when working with arrays.

>
> A = matrix(zeros(3,1)
> B = A * A.T
> B = [[ 0 0 0]
>        [0 0 0]
>        [0  0 0]]

Outer-product, 3x1 * 1x3 --> 3x3

>
> I would have thought that the result should have been [[0]]
> if I do the following:
> A = matrix([[0 0 0]]) Then A * A.T yields [[0]]

Inner-product, 1x3 * 3x1 --> 1x1

>
> Can someone tell me why and how I might fix this?
> Chris
>

Nothing to fix, just repeat matrix multiplication rules from your linear algebra textbook.

Sturla
```