Tensorflow.js是一个开放源代码库,由Google开发,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。
.clipByValue()函数用于查找指定张量输入的限幅值,并逐个元素地完成。
用法:
tf.clipByValue(x, clipValueMin, clipValueMax)
Parameters:
- x:它是张量输入,其值将被裁剪,并且可以是tf.Tensor,TypedArray或Array类型。
- clipValueMin:将被限制在规定范围的下限。
- clipValueMax:它是要裁剪的指定范围的上限。
返回值:它返回tf.Tensor对象。
范例1:在此示例中,我们定义了整数类型的输入张量,然后打印其裁切后的值。为了创建输入张量,我们使用.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 clipByValue() method and
// printing output
y.clipByValue(-11, 11).print();
输出:
Tensor [9, -10, -11, 11]
范例2:在此示例中,浮点类型值被视为张量输入,并且所有参数都直接传递给clipByValue函数。
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining float values
var val = [.5, 4.9, .275, -1.46];
// Calling tensor1d method
const y = tf.tensor1d(val);
// Calling clipByValue() method
var res = tf.clipByValue(y, -1, 1);
// printing output
res.print();
输出:
Tensor [0.5, 1, 0.275, -1]
相关用法
- PHP imagecreatetruecolor()用法及代码示例
- p5.js year()用法及代码示例
- d3.js d3.utcTuesdays()用法及代码示例
- PHP ImagickDraw getTextAlignment()用法及代码示例
- PHP Ds\Sequence last()用法及代码示例
- PHP array_udiff_uassoc()用法及代码示例
- PHP geoip_continent_code_by_name()用法及代码示例
- d3.js d3.map.set()用法及代码示例
- PHP GmagickPixel setcolor()用法及代码示例
- PHP opendir()用法及代码示例
- PHP cal_to_jd()用法及代码示例
- d3.js d3.bisectLeft()用法及代码示例
- PHP stream_get_transports()用法及代码示例
- PHP Ds\Deque pop()用法及代码示例
- PHP SimpleXMLElement children()用法及代码示例
- p5.js removeElements()用法及代码示例
注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Tensorflow.js tf.clipByValue() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。