📜  Tensorflow.js tf.addN()函数

📅  最后修改于: 2022-05-13 01:56:33.130000             🧑  作者: Mango

Tensorflow.js tf.addN()函数

Tensorflow.js是谷歌开发的一个开源库,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。

tf.addN()函数用于逐元素添加指定的张量列表。每个张量应具有相同的形状和数据类型。

句法:

tf.addN (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();


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
   [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