Tensorflow.js tf.dot()函数
Tensorflow.js是谷歌开发的一个开源库,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。
tf.dot()函数用于计算两个给定矩阵或向量 t1 和 t2 的点积。
句法:
tf.dot(t1, t2);
参数:此函数接受一个参数,如下所示:
- t1:点运算的第一个张量。
- t2:点运算的第二张量。
返回值:它返回两个给定矩阵或向量 t1 和 t2 的点积。
示例 1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
let geek1 = tf.tensor1d([2, 3]);
let geek2 = tf.tensor2d([[2, 3], [4, 5]]);
let geek3 = tf.tensor2d([[2, 3, 4], [5, 6, 7]]);
let a =geek1.dot(geek2);
let b =geek2.dot(geek1);
let c =geek2.dot(geek3);
a.print();
b.print();
c.print();
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
let geek1 = tf.tensor1d([3, 4]);
let geek2 = tf.tensor2d([[3, 4], [5, 6]]);
tf.dot(geek1, geek2).print();
输出:
Tensor
[16, 21]
Tensor
[13, 23]
Tensor
[[19, 24, 29],
[33, 42, 51]]
示例 2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
let geek1 = tf.tensor1d([3, 4]);
let geek2 = tf.tensor2d([[3, 4], [5, 6]]);
tf.dot(geek1, geek2).print();
输出:
Tensor
[29, 36]
参考: https://js.tensorflow.org/api/latest/#dot