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


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

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

tf.addN()函數用於按元素添加指定的Tensors列表。每個張量應具有相同的形狀和數據類型。

用法:

tf.addN (tensors)

參數:此函數接受如下所示的參數:

  • tensors:具有相同形狀和數據類型的指定張量的數組/列表。

返回值:它返回添加元素的張量。



範例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing some Tensors
const a = tf.tensor1d([0, 1, 2]);
const b = tf.tensor1d([3, 4, 5]);
  
// Calling the .addN() function over
// the above Tensors as its parameters
tf.addN([a, b]).print();

輸出:

Tensor
   [3, 5, 7]

範例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Using some Tensors as the parameter
// for the .addN() function 
tf.addN([[12, 5, 6], [3, 2, 5], [2, 7, 9]]).print();

輸出:

Tensor
   [17, 14, 20]

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

相關用法


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