2017-11-16 5 views
0

単純なプログラムでは、単純なタスクを実行できず、次のエラーが発生します。オブジェクトはテンソルフロー内の項目割り当てをサポートしていません

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) 

そして、私は次のエラーを取得する:

TypeError: 'Tensor' object does not support item assignment

答えて

1

テンソルオブジェクトは、インデックスによって変更/アクセスすることはできません。

ここで、固定コードです:

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) 
関連する問題