📜  Tensorflow.js tf.div()函数

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

Tensorflow.js tf.div()函数

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

tf.div()函数用于按元素划分两个指定的张量。它支持广播。

句法:

tf.div (a, b)

参数:此函数接受两个参数,如下所示:

  • a:第一个输入张量作为分子。
  • b:第二个输入张量作为分母。它必须与“a”具有相同的数据类型。

返回值:它为 a/b 的结果返回一个 Tensor,其中 a 是第一个 Tensor,b 是第二个 Tensor。

示例 1:

Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing two Tensors
const a = tf.tensor1d([3, 5, 10, 15]);
const b = tf.tensor1d([2, 5, 2, 7]);
  
// Calling the .div() function over the 
// above Tensors as its parameters
a.div(b).print();


Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Broadcasting the div a with b
const a = tf.tensor1d([1, 12, 17, 20]);
const b = tf.scalar(3);
  
// Calling the .div() function over the 
// above Tensors as its parameters
a.div(b).print();


输出:

Tensor
   [1.5, 1, 5, 2.1428571]

示例 2:

Javascript

// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Broadcasting the div a with b
const a = tf.tensor1d([1, 12, 17, 20]);
const b = tf.scalar(3);
  
// Calling the .div() function over the 
// above Tensors as its parameters
a.div(b).print();

输出:

Tensor
   [0.3333333, 3.9999998, 5.6666665, 6.666666]