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


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

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

tf.sqrt()函數用於返回指定張量元素的平方根。

用法:

tf.sqrt( x )

參數:該函數接受單個參數,如下所示:

  • x:指定的輸入張量。

返回值:它返回指定張量元素的平方根。



範例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
const x = tf.tensor1d([4, 9, 16, 25]);
  
// Calling the .sqrt() function over
// the above tensor as its parameter
x.sqrt().print();

輸出:

Tensor
   [2, 3, 4, 5]

範例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Using a tensor of some elements
// as the parameter for the .sqrt() function
tf.tensor1d([0, 1, 2, 1.7, 2.5]).sqrt().print();

輸出:

Tensor
   [0, 1, 1.4142135, 1.3038405, 1.5811388]

相關用法


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