Skip to content
Related Articles

Related Articles

Improve Article

Tensorflow.js tf.linalg.gramSchmidt() Function

  • Last Updated : 02 Jun, 2021
Geek Week

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:

  • xs ( a tf.Tensor1D array or tf.Tensor2D): These are the vectors that are to be orthogonalized.

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



Example 1:

Javascript




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:

Javascript




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

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :