# Week 2- Understanding Python Broadcasting

I’m a bit confused with Python broadcasting. It is not conducting matrices calculations. Is it only for array element wise calculations? Thanks!

Hi Ketyeth,

For multiplying two matrices, use the dot () method. Here is an introduction to numpy.dot( a, b, out=None)

Few specifications of numpy.dot:

• If both a and b are 1-D (one dimensional) arrays – Inner product of two vectors (without complex conjugation)
• If both a and b are 2-D (two dimensional) arrays – Matrix multiplication
• If either a or b is 0-D (also known as a scalar) – Multiply by using numpy.multiply(a, b) or a * b.
• If a is an N-D array and b is a 1-D array – Sum product over the last axis of a and b.
• If a is an N-D array and b is an M-D array provided that M>=2 – Sum product over the last axis of a and the second-to-last axis of b:

Also, dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])

If you still have questions let me know.

No, broadcasting can also allow you to perform an operation between a matrix and a vector, if the vector can be expanded to match the dimension of the matrix. I think I already gave you this example on another thread.