views:

78

answers:

1

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

+7  A: 

Taking advantage of broadcasting:

(a.T * b).T
Roberto Bonvallet
I think that's the transpose of what the question asked for.
Jon-Eric
@Jon-Eric: thanks, I fixed it.
Roberto Bonvallet
thanks - that works well
damien
@damien: You're welcome. I'd appreciate it if you mark my answer as accepted by clicking on the check mark on the left :)
Roberto Bonvallet