"valueerror: Setting An Array Element With A Sequence." Tensorflow
Solution 1:
First, the dimensionality of your x_
variable wrong: currently, it's of shape [2, 4]
, but you're attempting to use it in a slot that's expecting data of shape [4, 2]
.
Second, tf.Variable
is meant to represent literally a variable (in the mathematical sense) within your neural net model that'll be tuned as you train your model -- it's a mechanism for maintaining state.
To provide actual input to train your model, you can simply pass in a regular Python array (or numpy array) instead.
Here's a fixed version of your code that appears to do what you want:
import tensorflow as tf
sess = tf.Session()
x = tf.placeholder(tf.float32, shape=[4,2])
y = tf.nn.relu(x)
sess.run(tf.global_variables_initializer())
x_ = [[-9, -4], [6, 3], [-2, -1], [3, 10]]print(sess.run(y, feed_dict={x:x_}))
If you really did want a node within your neural net to start off initialized with those values, I'd get rid of the placeholder and use x_
directly:
import tensorflow as tf
sess = tf.Session()
x = tf.Variable([[-9, -4], [6, 3], [-2, -1], [3, 10]], dtype=tf.float32)
y = tf.nn.relu(x)
sess.run(tf.global_variables_initializer())
print(sess.run(y))
This is probably not what you meant to do, though -- it's sort of unusual to have a model that doesn't accept any input.
Post a Comment for ""valueerror: Setting An Array Element With A Sequence." Tensorflow"