Thursday, September 18, 2025
HomeLanguagesJavascriptTensorflow.js tf.dot() Function

Tensorflow.js tf.dot() 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.dot() function is used to compute the dot product of two given matrices or vectors, t1 and t2.

Syntax: 

tf.dot(t1, t2);

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

  • t1: It is the first tensor for the dot operation.
  • t2: It is the second tensor for the dot operation.

Return Value: It returns the dot product of two given matrices or vectors t1 and t2.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
let geek1 = tf.tensor1d([2, 3]);
let geek2 = tf.tensor2d([[2, 3], [4, 5]]);
let geek3 = tf.tensor2d([[2, 3, 4], [5, 6, 7]]);
  
let a =geek1.dot(geek2);
let b =geek2.dot(geek1);
let c =geek2.dot(geek3);
  
a.print();
b.print();
c.print();


Output:

Tensor
    [16, 21]
Tensor
    [13, 23]
Tensor
    [[19, 24, 29],
     [33, 42, 51]]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
let geek1 = tf.tensor1d([3, 4]);
let geek2 = tf.tensor2d([[3, 4], [5, 6]]);
  
tf.dot(geek1, geek2).print();


Output:

Tensor
    [29, 36]

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

RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6664 POSTS0 COMMENTS
Nicole Veronica
11837 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7054 POSTS0 COMMENTS
Thapelo Manthata
6737 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS