当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Tensorflow.js tf.expm1()用法及代码示例

Tensorflow.js是一个开放源代码库,由Google开发,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。

.expm1()函数用于查找减去张量输入的 index 值即1的(e^x-1),并且它是逐个元素地完成的。

用法:

tf.expm1(x)

Parameters: 

  • x:它是要计算其 index 值减去一的张量输入,它的类型可以是tf.Tensor,TypedArray或Array。

返回值:它返回tf.Tensor对象。



范例1:在此示例中,我们定义了整数类型的输入张量,然后输出减去其中之一的 index 值。为了创建输入张量,我们使用.tensor1d()方法,为了打印输出,我们使用.print()方法。

Javascript


// Importing the tensorflow.js library
//import * as tf from "@tensorflow/tfjs"
  
// Defining tensor input elements
const y = tf.tensor1d([5, 1, 8, 0]);
  
// Calling expm1() method and
// printing output
y.expm1().print();

输出:

Tensor
    [147.4131622, 1.7182819, 2979.9580078, 0]

范例2:在此示例中,浮点类型值被视为张量输入,并且参数直接传递给expm1函数。

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining float values
var val = [8.6, 0.5, .24];
  
// Calling tensor1d method
const y = tf.tensor1d(val);
  
// Calling expm1() method
var res = tf.expm1(y)
  
// printing output
res.print();

输出:

Tensor
    [5430.6616211, 0.6487213, 0.2712491]

参考:https://js.tensorflow.org/api/latest/#expm1

相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Tensorflow.js tf.expm1() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。