當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Tensorflow.js tf.linalg.gramSchmidt()用法及代碼示例

Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。

tf.linalg.gramSchmidt() 函數用於使用 Gram-Schimdt 過程對向量進行正交化。

用法:

tf.linalg.gramSchmidt( xs ) 

參數:

  • xs(tf.Tensor1D 數組或 tf.Tensor2D):這些是要正交化的向量。

返回值:它返回一個 tf.Tensor1D 數組或 tf.Tensor2D。



範例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();

輸出:

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

範例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();

輸出:

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

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

相關用法


注:本文由純淨天空篩選整理自parasmadan15大神的英文原創作品 Tensorflow.js tf.linalg.gramSchmidt() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。