TypeError: ‘Tensor‘ object does not support item assignment in TensorFlow

a = tf.zeros([3,3])

a[:,0:2] = 1

TypeError: ‘Tensor’ object does not support item assignment in TensorFlow

The reason for the error is that tensor can not be assigned directly. The solution is as follows

1. The variable tensor can be changed to:

a = tf.Variable(tf.zeros([3,3]))

a[:,0:2].assign(1)

2. Use numpy to process

b_list = []

b_list.append(a[:,0:2])

a = tf.stack(b_list)

undertake MATLAB, Python and C + + programming, machine learning, computer vision theory implementation and guidance, undergraduate and master can, salted fish trading, professional answer please go to know, for details, please contact QQ number 757160542, if you are the one

This article shares in the blog “Yu Xiaoyong” (CSDN).

Similar Posts: