在Tens中表示三维张量

2024-05-17 02:52:57 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在Tensorflow中表示三维稀疏张量? 对于2个维度,我使用

SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])

有结果吗

^{pr2}$

很难显示三维的视觉效果,但我会尽力的

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是怎么想让我写代码的


Tags: 代码tensorflowdensevaluesshape我会indices视觉效果
1条回答
网友
1楼 · 发布于 2024-05-17 02:52:57

你只是把]放错地方了。在

SparseTensor(indices=[[0, 0, 0], [1, 2, 0], [1,2,1]], values=[1,2,3], dense_shape=[3,4,2])

给你想要的矩阵。在

根据docs

dense_shape: A 1-D int64 tensor of dense_shape [ndims], which specifies the dense_shape of the sparse tensor. Takes a list indicating the number of elements in each dimension. For example, dense_shape=[3,6] specifies a two-dimensional 3x6 tensor, dense_shape=[2,3,4] specifies a three-dimensional 2x3x4 tensor, and dense_shape=[9] specifies a one-dimensional tensor with 9 elements.

相关问题 更多 >