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
import * as tf from "@tensorflow/tfjs"
let geek1 = tf.tensor2d([2, 1], [1, 2]);
let geek2 = tf.tensor2d([11, 12, 13, 14], [2, 2]);
geek1.matMul(geek2).print();
|
Output:
Tensor
[[35, 38],]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
let geek1 = tf.tensor2d([2, 1], [1, 2]);
let geek2 = tf.tensor2d([61, 62, 63, 64], [2, 2]);
tf.matMul(geek1, geek2).print();
|
Output:
Tensor
[[185, 188],]
Reference:https://js.tensorflow.org/api/latest/#matMul
Last Updated :
18 May, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...