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


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

Tensorflow.js是Google开发的开源库,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。

tf.sqrt()函数用于返回指定张量元素的平方根。

用法:

tf.sqrt( x )

参数:该函数接受单个参数,如下所示:

  • x:指定的输入张量。

返回值:它返回指定张量元素的平方根。



范例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
const x = tf.tensor1d([4, 9, 16, 25]);
  
// Calling the .sqrt() function over
// the above tensor as its parameter
x.sqrt().print();

输出:

Tensor
   [2, 3, 4, 5]

范例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Using a tensor of some elements
// as the parameter for the .sqrt() function
tf.tensor1d([0, 1, 2, 1.7, 2.5]).sqrt().print();

输出:

Tensor
   [0, 1, 1.4142135, 1.3038405, 1.5811388]

相关用法


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