Sorry Newbee in Tensorflow and Python I implemented this code to learn the sum of 9 random numbers. I'm getting an error which I can't understand.Unfortunately I could not find a similar problem in tutorials our here ...
import tensorflow as tf
import numpy as np
n_samples = 100
x = tf.placeholder(tf.float32, shape=[n_samples, 9])
y = tf.placeholder(tf.float32, shape=[n_samples])
x_value = tf.placeholder(tf.float32, shape=[n_samples, 9])
y_value = tf.placeholder(tf.float32, shape=[n_samples])
W = tf.Variable(tf.zeros([9, 1]))
b = tf.Variable(0.0)
y = tf.matmul(x, W) + b
y_pred = tf.placeholder(tf.float32, shape=[n_samples])
cost = tf.reduce_sum((y - y_pred)**2 / n_samples)
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cost)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
x_value = np.random.uniform(0, 1, size = (n_samples, 9))
y_value = np.random.uniform(0, 1, size = (n_samples))
for i in range(n_samples):
mysum = 0.0
print (i)
for j in range(9):
print (x_value[i][j])
mysum += x_value[i][j]
y_value[i] = mysum
print (y_value[i])
cost = sess.run( train_step, feed_dict={x: x_value, y: y_value} )
print (cost)
And I'm getting this error:
ValueError: Cannot feed value of shape (100,) for Tensor u'add:0', which has shape '(100, 1)'
Any help is appreciated.