在之前的简单程序中,我无法执行简单的任务并收到以下错误。
import tensorflow as tf
x_1= tf.constant([1, 2, 3])
x_1= tf.reshape(x_1, shape= (1, 3))
x_2= tf.constant([2, 3, 4])
x_2= tf.reshape(x_2, shape= (1, 3))
x_3= tf.constant([3, 4, 5])
x_3= tf.reshape(x_3, shape= (1, 3))
x= tf.concat((x_1, x_2, x_3), axis=0)
for i in range(0, 3):
x[i, :]= x[i, :]+ 1
init= tf.global_variables_initializer()
with tf.Session() as sess:
y= sess.run(x)
我收到以下错误:
类型错误:“张量”对象不支持项目分配
张量对象无法通过索引访问/修改。
这是修复的代码:
import tensorflow as tf
x_1 = tf.constant([1, 2, 3])
x_1 = tf.reshape(x_1, shape=(1, 3))
x_2 = tf.constant([2, 3, 4])
x_2 = tf.reshape(x_2, shape=(1, 3))
x_3 = tf.constant([3, 4, 5])
x_3 = tf.reshape(x_3, shape=(1, 3))
x = tf.concat((x_1, x_2, x_3), axis=0)
x = tf.add(x, tf.constant(1, shape=x.shape))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
y = sess.run(x)
print(y)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)