1
假设我有一个列表创建布尔面具
x = [0, 1, 3, 5]
而且我想与尺寸
s = (10, 7)
使得x
定义的索引行的第一列是一个张量1,否则为0。
对于这个特殊的例子,我想获得含有张量:
T = [[1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]]
使用numpy的,这将是等价的:
t = np.zeros(s)
t[x, 0] = 1
我发现这个related answer,但它不真的解决了我的问题。
谢谢!你知道我可以如何动态设置dense_shape吗?我在这里问过这个问题https://stackoverflow.com/questions/44650464/tensorflow-sparsetensor-with-dynamically-set-dense-shape –
当然。在您发送的链接上发布答案 – MZHm