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


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

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

tf.notEqual()函數用於返回布爾值的張量,即,如果第一個張量的值不等於第二個張量的值,則返回true;否則返回false。它支持廣播。

用法:

tf.notEqual(a, b)

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

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

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



範例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing some tensors
const a = tf.tensor1d([1, 2, 3, 4]);
const b = tf.tensor1d([1, 4, 3, 4]);
  
// Calling the .notEqual() function
a.notEqual(b).print();

輸出:

Tensor
   [false, true, false, false]

範例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Using tensors of some values as
// the parameters of .notEqual() function
tf.tensor1d([0.1, 2.06, 2.1, 3.0]).notEqual(
tf.tensor1d([.1, 2.6, 2.0, 3])).print();

輸出:

Tensor
   [false, true, true, false]

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

相關用法


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