Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-020

Hadamard Product

Problem

Compute the elementwise (Hadamard) product of two matrices A and B of the same shape.

C[i][j] = A[i][j] * B[i][j].

Hint

This is not matrix multiplication; multiply matching positions only.

Test cases

case 1
in: [[[1,2],[3,4]],[[5,6],[7,8]]]
expected: [[5,12],[21,32]]
case 2
in: [[[2,0],[1,-1]],[[0,3],[4,5]]]
expected: [[0,0],[4,-5]]
case 3
in: [[[1,1,1]],[[2,3,4]]]
expected: [[2,3,4]]
case 4
in: [[[2]],[[3]]]
expected: [[6]]
Starter codePython
def hadamard_product(A, B):
    # Your code here
    pass

4 test cases · run your code against them in the editor