Open In App

Tensorflow.js tf.linalg.gramSchmidt() 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.linalg.gramSchmidt() function is used to orthogonalize the vectors using the Gram-Schimdt process.



Syntax:

tf.linalg.gramSchmidt( xs ) 

Parameters:



Return Value: It returns a tf.Tensor1D array or tf.Tensor2D.

Example 1:




const tf = require("@tensorflow/tfjs")
  
// Creating a 2-D tensor
const input = tf.tensor2d([
    [3, 7], 
    [4, 6]
]);
  
// Getting the orthogonalized vector
let result = tf.linalg.gramSchmidt(input);
  
result.print();

Output:

Tensor
    [[0.3939193, 0.919145  ],
     [0.919145 , -0.3939194]]

Example 2:




const tf = require("@tensorflow/tfjs")
  
// Creating a 2-D tensor
const input = tf.tensor2d([
    [5, 7, 2], 
    [7, 6, 9],
    [1, 2, 3]
]);
  
// Getting the orthogonalized vector
let result = tf.linalg.gramSchmidt(input);
  
result.print();

Output:

Tensor
    [[0.5661386, 0.792594  , 0.2264554],
     [0.1283516, -0.3561312, 0.925579 ],
     [-0.814256, 0.4949402 , 0.3033505]]

Reference: https://js.tensorflow.org/api/latest/#linalg.gramSchmidt

Article Tags :