how to multiply two matrices with different size?

limetree377 at gmail.com limetree377 at gmail.com
Fri Nov 18 20:51:34 EST 2016


Hi :)
I'm trying to multiply two matrices that has different size.

-------------------------------------code-------------------------

import numpy as np

a = np.random.randn(4, 3)
b = np.random.randn(4, 1)

print a
print b

-------------------------------------code-------------------------

How should I multiply a and b so that the multipled matrix's size is 4*3?

I want to multiply matrix 'b' to each row of matrix 'a'.
So that if matrix a is
[[1, 2, 3],
  [2, 3, 4]]
and b is
[[2],
[3]]
a*b is
[[2, 4, 6],
  [4, 6 ,8]]

Plz help me!

if possible, plz use numpy



More information about the Python-list mailing list