Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy matrix multiplication

I am trying to figure out how to do a kind of scalar matrix multiplication in numpy.

I have

a = array(((1,2,3),(4,5,6)))
b = array((11,12))

and i want to do

a op b

to result in

array(((1*11,2*11,3*11),(4*12,5*12,6*12))

right now I am using the following expression

c= a * array((b, b, b)).transpose()

It seems like there must be a more efficient way of doing this though

like image 493
damien Avatar asked Feb 27 '23 04:02

damien


1 Answers

Taking advantage of broadcasting:

(a.T * b).T
like image 158
Roberto Bonvallet Avatar answered Mar 07 '23 13:03

Roberto Bonvallet