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


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

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

tf.less()函數用於為兩個指定的張量值返回布爾值的張量,即,如果第一個張量的值小於第二張量的值,則返回true;否則返回false。它支持廣播。

用法:

tf.less(a, b)

參數:此函數接受兩個參數,如下所示:

  • a:第一個輸入張量。
  • b:第二個輸入張量。它應該具有與Tensor “a”相同的數據類型的值。

返回值:它返回布爾值的張量,即如果第一個張量的值小於第二張量的值,則返回true;否則返回false。



範例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing two different tensors
const a = tf.tensor1d([2, 3, 6, 8]);
const b = tf.tensor1d([1, 4, 5, 9]);
  
// Calling the .less() function
a.less(b).print();

輸出:

Tensor
   [false, true, false, true]

範例2:

Javascript


// Importing the tensorflow library
import * as tf from "@tensorflow/tfjs"
  
// Calling the .less() function with two
// Different tensors as its parameters
tf.tensor1d([1.5, 2.060, 2, 0.05, 4.5]).
less(tf.tensor1d([1.25, 2.60, 2.0, .5, 4.05])).print();

輸出:

Tensor
   [false, true, false, true, false]

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

相關用法


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