参考:https://www.w3cschool.cn/tensorflow_python/tensorflow_python-le4w2kjm.html
SparseTensor:稀疏张量
之前一直不知道张量说的是什么,查了才知道原来就是说的Tensor,一般一维的张量表示为向量,二维的张量表示为矩阵
稀疏张量SparseTensor(indices, values, dense_shape)包括以下组件,其中N和ndims分别是在SparseTensor中的值的数目和维度的数量:
- indices:density_shape[N, ndims]的2-D int64张量,指定稀疏张量中包含非零值(元素为零索引)的元素的索引。例如,indices=[[1,3], [2,4]]指定索引为[1,3]和[2,4]的元素具有非零值。
- values:任何类型和dense_shape [N]的一维张量,它提供了indices中的每个元素的值。例如,给定indices=[[1,3], [2,4]]的参数values=[18, 3.6]指定稀疏张量的元素[1,3]的值为18,张量的元素[2,4]的值为3.6。
- dense_shape:density_shape[ndims]的一个1-D int64张量,指定稀疏张量的dense_shape。获取一个列表,指出每个维度中元素的数量。例如,dense_shape=[3,6]指定二维3x6张量,dense_shape=[2,3,4]指定三维2x3x4张量,并且dense_shape=[9]指定具有9个元素的一维张量。
例如:稀疏张量表示:
SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])
表示稠密张量:
[[1, 0, 0, 0]
[0, 0, 2, 0]
[0, 0, 0, 0]]