Tensorflow.js tf.ceil()函数
Tensorflow.js 是一个开源库,由 Google 开发,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。
.ceil()函数用于查找所述张量输入的上限,并按元素完成。
句法 :
tf.ceil(x)
参数:
- x:要计算ceil值的张量输入,类型可以是tf.Tensor ,也可以是TypedArray ,也可以是Array 。
返回值:它返回 tf.Tensor 对象。
示例 1:在此示例中,我们定义了一个整数类型的输入张量,然后打印它的 ceil 值。为了创建输入张量,我们使用.tensor1d()方法,为了打印输出,我们使用.print()方法。
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining tensor input elements
const y = tf.tensor1d([9, 10, 19, 12]);
// Calling ceil() method and
// printing output
y.ceil().print();
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining float values
var val = [.5, 4.9, .275];
// Calling tensor1d method
const y = tf.tensor1d(val);
// Calling ceil() method
var res = tf.ceil(y)
// Printing output
res.print();
输出:
Tensor
[9, 10, 19, 12]
示例 2:在此示例中,浮点类型值被视为张量输入,参数直接传递给ceil函数。
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining float values
var val = [.5, 4.9, .275];
// Calling tensor1d method
const y = tf.tensor1d(val);
// Calling ceil() method
var res = tf.ceil(y)
// Printing output
res.print();
输出:
Tensor
[1, 5, 1]
参考: https://js.tensorflow.org/api/latest/#ceil