假设Tensor包含:
[[0 0 1]
[0 1 0]
[1 0 0]]
Run Code Online (Sandbox Code Playgroud)
如何以本机方式获得密集表示(不使用numpy或迭代)?
[2,1,0]
Run Code Online (Sandbox Code Playgroud)
有tf.one_hot()反过来,也tf.sparse_to_dense()有似乎这样做,但我无法弄清楚如何使用它.
vec = tf.constant([[0, 0, 1], [0, 1, 0], [1, 0, 0]])
locations = tf.where(tf.equal(vec, 1))
# This gives array of locations of "1" indices below
# => [[0, 2], [1, 1], [2, 0]])
# strip first column
indices = locations[:,1]
sess = tf.Session()
print(sess.run(indices))
# => [2 1 0]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3859 次 |
| 最近记录: |