tensorflow中有没有什么方法可以实现对矩阵的广播分配(tf.变量) 类似下面的代码。。。。在
a = tf.Variable(np.zeros([10,10,10,10], np.int32))
# creating a mask and trying to assign the 2nd, 3rd dimension of a
mask = tf.ones([10,10])
# 1) which is work in this case, but only assign one block
op = a[0,:,:,0].assign(mask)
# 2) attempting to broadcasting while not work, size mismatch
op = a[0].assign(mask)
对我来说,当前的解决方案可能会迭代所有其他维度,但可能会遭遇嵌套循环,如1) 或者一定有更聪明的方法来做,谢谢!在
不是一个通用的解决方案(大量的硬编码张量形状),但希望这能为您的示例提供要点:
相关问题 更多 >
编程相关推荐