Write a program to calculate the element-wise product of two matrices.
MediumProblem Statement
Write a program to calculate the element-wise product of two matrices.
Sample Input
Matrix 1: [,1] [,2] [1,] 1 2 [2,] 3 4 Matrix 2: [,1] [,2] [1,] 5 6 [2,] 7 8
Sample Output
[,1] [,2] [1,] 5 21 [2,] 12 32
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
# Predefined structure
matrix1 <- # Create the first matrix
matrix2 <- # Create the second matrix
product <- # Perform element-wise multiplication
print(product)
Input
Matrix 1: [,1] [,2] [1,] 1 2 [2,] 3 4 Matrix 2: [,1] [,2] [1,] 5 6 [2,] 7 8
Expected Output
[,1] [,2] [1,] 5 21 [2,] 12 32