Skip to content
Related Articles

Related Articles

Ruby | Matrix entrywise_product() function
  • Last Updated : 07 Jan, 2020

The entrywise_product() is an inbuilt method in Ruby returns the hadamard_product of two matrices. It takes two matrices of the same dimensions and produces another matrix of the same dimension as the operands where each element i, j is the product of elements i, j of the original two matrices.

Syntax: mat1.entrywise_product(mat2)

Parameters: The function needs two matrix whose hadamard_product is to be done.

Return Value: It returns the hadamard_product of two matrices.

Example 1:






# Ruby program for entrywise_product() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 =  Matrix[[1, 21], [31, 18]]  
mat2 =  Matrix[[1, 3], [3, 4]]   
   
# prints entrywise_product 
puts  mat1.entrywise_product(mat2)

Output:

Matrix[[1, 63], [93, 72]]

Example 2:




# Ruby program for entrywise_product() method in Matrix
  
# Include matrix 
require "matrix"
  
# Initialize a matrix 
mat1 =  Matrix[[1, 31], [13, 28], [3, 4]]  
mat2 =  Matrix[[32, 3], [32, 74], [43, 3]]   
  
# prints entrywise_product 
puts  mat1.entrywise_product(mat2)

Output:

Matrix[[32, 93], [416, 2072], [129, 12]]

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :