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 公布
发表回复