DLS Course 1 week 2 quiz

When creating a post, please add:

a=np.random.randn(3,3)
b=np.random.randn(3,1)
c=a∗b
What will be c? (If you’re not sure, feel free to run this in python to find out).

I don’t understand the answer, which one is correct ? I did try out the code on jupyter lab, it did ran fine and seems broadcasting ? Why the answer says incorrect ? or a “dot product” is “real broadcasting” ?

f = np.random.randn(3, 3)
g = np.random.randn(3, 1)

print(f)
print(g)

h = f * g
print(h)

[[ 1.0018774 0.75395032 0.20840968]
[-0.43446762 -0.91685108 0.06553869]
[ 2.41612123 0.56578568 1.21728828]]
[[ 1.56902888]
[-0.51308923]
[-0.57096744]]

[[ 1.57197458 1.18296982 0.32700081]
[ 0.22292065 0.47042642 -0.0336272 ]
[-1.37952656 -0.3230452 -0.69503198]]

1 Like

the answer you selected is incorrect because it states invokes a matrix multiplication operation
but once you perform use numpy it performs operations element-by-element, so multiplying 2D arrays with * operator is not a matrix multiplication – it’s an element-by-element multiplication

hence answer would be the next option

4 Likes

Thanks @Deepti_Prasad for clarification. After chewing over the description, I guess I misunderstood what they mean.

2 Likes

The ‘*’ operator is element-wise multiplication.

1 Like