【发布时间】:2017-03-19 05:56:42
【问题描述】:
以下代码通过索引向张量内的特定位置添加一些内容(感谢@mrry 的回答here)。
indices = [[1, 1]] # A list of coordinates to update.
values = [1.0] # A list of values corresponding to the respective
# coordinate in indices.
shape = [3, 3] # The shape of the corresponding dense tensor, same as `c`.
delta = tf.SparseTensor(indices, values, shape)
例如,给定这个 -
c = tf.constant([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]])
它会在 [1, 1] 处加 1,结果是
[[0.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 0.0]])
问题 - 是否可以在特定位置替换值而不是在该位置添加?如果在 tensorflow 中不可以,在任何其他类似的库中是否可以?
例如,
鉴于此-
[[4.0, 43.1.0, 45.0],
[2.0, 22.0, 6664.0],
[-4543.0, 0.0, 43.0]])
有没有办法将 [1, 1] 处的 22 替换为(比如说)45,结果如下?
[[4.0, 43.1.0, 45.0],
[2.0, 45.0, 6664.0],
[-4543.0, 0.0, 43.0]])
【问题讨论】:
标签: python tensorflow