I have two array a
and b
such that b's shape is a row of a
. I want to multiply b
to each row of a
so for example,
#a
[[1,2,3]
[4,5,6]
[7,8,9]]
#b
[1,3,2]
# a times b
[[1,6,6]
[4,15,12]
[7,24,18]]
Is there any way to perform it?
I have two array a
and b
such that b's shape is a row of a
. I want to multiply b
to each row of a
so for example,
#a
[[1,2,3]
[4,5,6]
[7,8,9]]
#b
[1,3,2]
# a times b
[[1,6,6]
[4,15,12]
[7,24,18]]
Is there any way to perform it?
This is actually the expected output when using numpy. So in your case:
import numpy as np
a = np.array([[1,2,3], [4,5,6], [7,8,9]])
b = np.array([1,3,2])
c = a*b
c will be:
array([[ 1, 6, 6],
[ 4, 15, 12],
[ 7, 24, 18]])