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


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

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

.cosh()函数用于查找指定张量输入的双曲余弦,并且逐元素完成。

用法:

tf.cosh(x)

Parameters: 

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

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



范例1:在这个例子中,我们定义一个整数类型的输入张量,然后打印它的cosh值。为了创建输入张量,我们使用.tensor1d()方法,为了打印输出,我们使用.print()方法。

Javascript


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

输出:

Tensor
    [1.5430806, 548.3170776, 1, 10.0676613]

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

Javascript


// Importing the tensorflow.js library 
import * as tf from "@tensorflow/tfjs"
  
// Defining float values
var val = [1.5, .4, .22];
  
// Calling tensor1d method
const y = tf.tensor1d(val);
  
// Calling cosh() method
var res = tf.cosh(y)
  
// Printing output
res.print();

输出:

Tensor
    [2.3524094, 1.0810723, 1.0242977]

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

相关用法


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