manipulate Tensor by indices and values in TensorFlow | بلاگ

manipulate Tensor by indices and values in TensorFlow

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

Given tensor like:

SparseTensorValue(indices=array([[0, 0], [1, 0], [1, 1], [1, 2]]),
                  values=array([2, 0, 2, 5]),
                  dense_shape=array([2, 3]))

the shape is 2x3

| 2 na na |
| 0  2  5 |

Need a new tensor with value in the index, like below:

Note that the total num of values is 6 (set of [0, 1, 2, 3, 4, 5]) the shape is 2x6

| 0 0 1 0 0 0 |
| 1 0 1 0 0 1 |

The tensor can be created by the code below:

SparseTensorValue(indices=array([[0, 2], [1, 0], [1, 2], [1, 5]]),
                  values=array([2, 0, 2, 5]),
                  dense_shape=array([2, 6]))

How to do it in TensorFlow way for the Python style process below?

new_tensor = [(indices[i][0], values[i]) for i in range(len(indices))]
asked 28 secs ago
fengda

...
نویسنده : استخدام کار بازدید : 9 تاريخ : پنجشنبه 23 فروردين 1397 ساعت: 1:14