Friday, June 12, 2026
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
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS