title: Tensorflow InvalidArgumentError (see above for traceback): Incompatible shapes: [10000,10] vs. [10000]
body: <p>I'm trying my first attempt at tensorflow - I'm attempting to learn a linear regressor by taking an input vector of 10 dimensions, X and outputting a scalar, Y. Specifically I'm trying to use the closed-form gradient based solution.</p>
  
  <p>I've received the following error and I'm not sure what I've done wrong. Anything to point me in the right direction would be greatly appreciated!</p>
  
  <pre><code>PS C:\Users\Dave\Documents\School\Deep Learning\Assignment_1&gt; python test1.py
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfu
  lly opened CUDA library cublas64_80.dll locally
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfu
  lly opened CUDA library cudnn64_5.dll locally
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfu
  lly opened CUDA library cufft64_80.dll locally
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfu
  lly opened CUDA library nvcuda.dll locally
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfu
  lly opened CUDA library curand64_80.dll locally
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:885] F
  ound device 0 with properties:
  name: GeForce GTX 1080
  major: 6 minor: 1 memoryClockRate (GHz) 1.86
  pciBusID 0000:01:00.0
  Total memory: 8.00GiB
  Free memory: 6.63GiB
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:906] D
  MA: 0
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:916] 0
  :   Y
  I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:975] C
  reating TensorFlow device (/gpu:0) -&gt; (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
  Traceback (most recent call last):
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 10
      return fn(*args)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 10
      status, run_metadata)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\contextlib.py", line 66, in __exit__
      next(self.gen)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py",
  n_on_not_ok_status
      pywrap_tensorflow.TF_GetCode(status))
  tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [10000,10] vs. [10000]
           [[Node: sub = Sub[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Add, _recv_Placeholder_1_0/_7)]]
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "test1.py", line 43, in &lt;module&gt;
      c = sess.run(cost, feed_dict={X: train_X, Y: train_Y})
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 76
      run_metadata_ptr)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 96
      feed_dict_string, options, run_metadata)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 10
      target_list, options, run_metadata)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 10
      raise type(e)(node_def, op, message)
  tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [10000,10] vs. [10000]
           [[Node: sub = Sub[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Add, _recv_Placeholder_1_0/_7)]]
  
  Caused by op 'sub', defined at:
    File "test1.py", line 25, in &lt;module&gt;
      cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\math_ops.py", line 814,
      return func(x, y, name=name)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line
      result = _op_def_lib.apply_op("Sub", x=x, y=y, name=name)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py
      op_def=op_def)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 224
      original_op=self._default_original_op, op_def=op_def)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 112
      self._traceback = _extract_stack()
  
  InvalidArgumentError (see above for traceback): Incompatible shapes: [10000,10] vs. [10000]
           [[Node: sub = Sub[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Add, _recv_Placeholder_1_0/_7)]]
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>import numpy as np
  import tensorflow as tf
  import matplotlib.pyplot as plt
  rng = np.random
  
  #from IPython import get_ipython
  #get_ipython().run_line_magic('matplotlib', 'inline')
  
  learning_rate = 0.01
  training_epochs = 1000
  display_step = 50
  
  train_X = np.loadtxt('data.txt', usecols=[0,1,2,3,4,5,6,7,8,9])
  train_Y = np.loadtxt('data.txt', usecols=[10])
  n_samples = train_X.shape[0]
  X = tf.placeholder(tf.float32)
  Y = tf.placeholder(tf.float32)
  W = tf.Variable(rng.randn(), name = "weight")
  b = tf.Variable(rng.randn(), name = "bias")
  
  #build the model
  pred = tf.add(tf.mul(X,W), b)
  
  #mean squared error
  cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples)
  
  #gradient descent 
  optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
  
  #initialize the variables
  init = tf.global_variables_initializer()
  #launch the graph
  with tf.Session() as sess:
      sess.run(init)
  
      #fit training data
      for epoch in range(training_epochs):
          for (x, y) in zip(train_X, train_Y):
              sess.run(optimizer, feed_dict = {X: x, Y: y})
  
          #display logs
          if (epoch+1) % display_step ==0:
              c = sess.run(cost, feed_dict={X: train_X, Y: train_Y})
             # print "Epoch:", '%04d' % (epoch+1), "cost=", "{:.9f".format(c), \
                  #"W=", sess.run(W), "b=" sess.run(b)
  
      #print "Optimization done"
      training_cost = sess.run(cost, feed_dict={X: train_X, Y: train_Y})
      #print "Training cost=", training_cost, "W=", sess.run(W), "b=" sess.run(b), '\n'
  
      #display graphically
      plt.plot(train_X, train_Y, 'ro', label = 'Orig data')
      plt.plot(train_X, sess.run(W) * train_X + sess.run(b), label = 'Fitted Line')
      plt.legend()
      plt.show()
  </code></pre>