TensorFlow中的Tensor是什么

本篇文章给大家分享的是有关TensorFlow中的Tensor是什么,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

Tensor(张量)

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

  • Tensor实际上就是一个多维数组(multidimensional array)

  • Tensor的目的是能够创造更高维度的矩阵、向量。

TensorFlow中的Tensor是什么

色彩的例子

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

TensorFlow中的Tensor是什么

多维数组

TensorFlow中的Tensor是什么

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

TensorFlow中的Tensor是什么

更高维的张量:

TensorFlow中的Tensor是什么

初始化一个向量

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();


以上就是TensorFlow中的Tensor是什么,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。