Thursday, July 4, 2024
HomeLanguagesJavascriptTensorflow.js tf.matMul() Function

Tensorflow.js tf.matMul() Function

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.

The tf.matMul() function is used to compute the dot product of two matrices, A * B.

Syntax:

tf.matMul (a, b, transposeA?, transposeB?)

Parameters: This function accepts a parameter which is illustrated below:

  • a: This is the first matrix in dot product operation.
  • b: This is the second matrix in dot product operation.
  • transposeA: This is optional and if it is set to true, then a is transposed before multiplication.
  • transposeB: This is optional and if it is set to true, then b is transposed before multiplication.

Return Value: It returns the dot product of two matrices.

Below are the examples that illustrates the use of tf.matMul() function.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
let geek1 = tf.tensor2d([2, 1], [1, 2]);
let geek2 = tf.tensor2d([11, 12, 13, 14], [2, 2]);
  
// Calling the .avgPool3d() function over
// the above tensor as its parameter and 
// printing the result.
geek1.matMul(geek2).print();


Output:

Tensor
     [[35, 38],]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
let geek1 = tf.tensor2d([2, 1], [1, 2]);
let geek2 = tf.tensor2d([61, 62, 63, 64], [2, 2]);
  
// Calling the .avgPool3d() function over
// the above tensor as its parameter and 
// printing the result.
tf.matMul(geek1, geek2).print();


Output:

Tensor
     [[185, 188],]

Reference:https://js.tensorflow.org/api/latest/#matMul

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments