Tensorflow.js tf.minimum()函数
Tensorflow.js是谷歌开发的一个开源库,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。
tf.minimum()函数用于按元素返回两个指定张量的最小值。它支持广播。
句法:
tf.minimum (a, b)
参数:此函数接受两个参数,如下所示:
- a:第一个指定的张量。
- b:第二个指定张量。它必须具有与“a”相同的数据类型。
返回值:它返回两个指定张量“a”和“b”元素中的最小值。
示例 1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Initializing two tensors
const a = tf.tensor1d([3, 5, 7, 9]);
const b = tf.tensor1d([1, 6, 8, 2]);
// Calling the .minimum() function
a.minimum(b).print();
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Using two tensors as the parameter
// for the .minimum() function
tf.tensor1d([3, 5, 7, 9]).minimum(tf.tensor1d([6])).print();
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Broadcasting minimum a with b
const a = tf.tensor1d([1, 2, 7, 3, 4]);
const b = tf.scalar(4);
// Calling the .minimum() function
a.minimum(b).print();
输出:
Tensor
[1, 5, 7, 2]
示例 2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Using two tensors as the parameter
// for the .minimum() function
tf.tensor1d([3, 5, 7, 9]).minimum(tf.tensor1d([6])).print();
输出:
Tensor
[3, 5, 6, 6]
示例 3:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Broadcasting minimum a with b
const a = tf.tensor1d([1, 2, 7, 3, 4]);
const b = tf.scalar(4);
// Calling the .minimum() function
a.minimum(b).print();
输出:
Tensor
[1, 2, 4, 3, 4]
参考: https://js.tensorflow.org/api/latest/#minimum