x是形状的张量[32,32,3]
Y是形状的张量[1,320,320,3]
我们可以将Y,Y [0,:32,:32,:] = x更新为张量流操作吗?
答案 0 :(得分:0)
是的,你可以。你有没有测试过它?
切片也是张量。使用:
Y[0,:32,:32,:].assign(x)
1D中的示例,以便我们可以清楚地看到发生了什么:
import numpy as np
import tensorflow as tf
x = tf.Variable(np.zeros((2,)))
Y = tf.Variable(np.ones((10,)))
block_update = Y[4:6].assign(x)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print('old', Y.eval(sess))
sess.run(block_update)
print('new', Y.eval(sess))
输出:
old [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
new [ 1. 1. 1. 1. 0. 0. 1. 1. 1. 1.]