如何在Tensorflow中表示三维稀疏张量?对于2维,我使用
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]]很难显示三维的视觉效果,但我会尝试的
SparseTensor(indices=[[0, 0, 0], [0, 1, 2]], [1,1,2], values=[1, 2,3], dense_shape=[3, 4,2])
[[1, 0, 0, 0]
[0, 0, 2, 0]
[0, 0, 0, 0],
[0, 0, 0, 0]
[0, 0, 3, 0]
[0, 0, 0, 0]]这是我想要的。有人能帮我吗?我想不出SparseTensor想要我怎么写代码
发布于 2017-03-22 13:56:27
你只是把一个]放错地方了。
SparseTensor(indices=[[0, 0, 0], [1, 2, 0], [1,2,1]], values=[1,2,3], dense_shape=[3,4,2])给你想要的矩阵。
根据文档,
dense_shape: dense_shape ndims的一维int64张量,它指定稀疏张量的dense_shape .获取一个列表,指示每个维度中的元素数。例如,dense_shape=3,6指定一个二维3x6张量,dense_shape=2,3,4指定一个三维2x3x4张量,dense_shape=9指定一个包含9个元素的一维张量。
https://stackoverflow.com/questions/42953282
复制相似问题