关于javascript:TensorFlow中的Tensor是什么

4次阅读

共计 848 个字符,预计需要花费 3 分钟才能阅读完成。

Tensor(张量)

“张量”一词最后由威廉·罗恩·哈密顿在 1846 年引入。对,就是那个创造四元数的哈密顿:

  • Tensor 实际上就是一个多维数组(multidimensional array)
  • Tensor 的目标是可能发明更高维度的矩阵、向量。

色调的例子

彩色图像文件(RGB)个别都会解决成 3 -d tensor,每个 2d array 中的 element 示意一个像素,R 代表 Red,G 代表 Green,B 代表 Blue

多维数组

把三维张量画成一个立方体:

更高维的张量:

初始化一个向量

0 维

tf.tensor(1).print();

1 维

tf.tensor([1, 2, 3, 4]).print();
// or
tf.tensor1d([1, 2, 3]).print();

2 维

tf.tensor([[1, 2], [3, 4]]).print();
// or
tf.tensor2d([[1, 2], [3, 4]]).print();

3 维

tf.tensor([[[1], [2]], [[3], [4]]]).print();
// or
tf.tensor3d([[[1], [2]], [[3], [4]]]).print();

4 维

tf.tensor([[[[1], [2]], [[3], [4]]]]).print();
// or
tf.tensor4d([[[[1], [2]], [[3], [4]]]]).print();

5 维

tf.tensor([[[[[1], [2]], [[3], [4]]]]]).print();
// or
tf.tensor5d([[[[[1], [2]], [[3], [4]]]]]).print();

6 维

tf.tensor([[[[[[1],[2]],[[3],[4]]],[[[5],[6]],[[7],[8]]]]]]).print();
// or
tf.tensor6d([[[[[[1],[2]],[[3],[4]]],[[[5],[6]],[[7],[8]]]]]]).print();

本文由博客群发一文多发等经营工具平台 OpenWrite 公布

正文完
 0