Wednesday, November 12, 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
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6763 POSTS0 COMMENTS
Nicole Veronica
11916 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11983 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6834 POSTS0 COMMENTS
Umr Jansen
6838 POSTS0 COMMENTS