title: Python TensorFlow Error - Op needs to be operation [[1], [0]]
body: <p>I have made a function that converts variables like tuples, strings, and integers to a TensorFlow tensor and I am trying to convert said variables to a tensor in a function initializeTheory in a variable named lengthMatrix from a class named createNewTheory.  I am getting a error named TypeError: op needs to be an operation [[<a href="https://stackoverflow.com/questions/47750300/tensorflow-cant-convert-operation-to-tensor">1</a>] [<a href="https://stackoverflow.com/questions/43290373/what-does-tensorflow-op-do">2</a>]], I have tried to convert it to the same dtype as the one found in convToTfTensor down below, tried to switch the dtype to see if that would change anything, tried to set the operation in the lengthMatrix variable to be a singular integer, and I have also tried to look at other posts about similar problems such as this one but I have not found any that are specific to my problem.</p>
  <p>Here are some links to a few posts that I had looked at that do not fit within the bounds of my problem:</p>
  <p><a href="https://stackoverflow.com/questions/47750300/tensorflow-cant-convert-operation-to-tensor">Tensorflow - Can&#39;t convert Operation to Tensor</a></p>
  <p><a href="https://stackoverflow.com/questions/43290373/what-does-tensorflow-op-do">What does tensorflow &quot;op&quot; do?</a></p>
  <p>Here is the error that I am getting when I run the script in it's entirety:</p>
  <pre><code>Exception has occurred: TypeError
  op needs to be an Operation: [[1]
   [2]]
    File &quot;C:\Users\trevo\OneDrive\Desktop\VegaAiTest\utilityTheroy.py&quot;, line 53, in convToTfTensor
      newTensor = tf.Tensor(variable, 1, dtype=np.int32)
    File &quot;C:\Users\trevo\OneDrive\Desktop\VegaAiTest\utilityTheroy.py&quot;, line 131, in initalizeTheory
      y = convToTfTensor(lengthMatrix)
    File &quot;C:\Users\trevo\OneDrive\Desktop\VegaAiTest\utilityTheroy.py&quot;, line 122, in __init__
      self.initalizeTheory()
    File &quot;C:\Users\trevo\OneDrive\Desktop\VegaAiTest\utilityTheroy.py&quot;, line 166, in processTheorys
      self.newTheory = createNewTheory(self.wolfData, self.sigmoid)
    File &quot;C:\Users\trevo\OneDrive\Desktop\VegaAiTest\utilityTheroy.py&quot;, line 162, in __init__
      self.processTheorys()
    File &quot;C:\Users\trevo\OneDrive\Desktop\VegaAiTest\VegaMain.py&quot;, line 194, in searchData
      util.theoryHub(self.subDataFrameWithDummyData, 'leakyRelu', None)
    File &quot;C:\Users\trevo\OneDrive\Desktop\VegaAiTest\VegaMain.py&quot;, line 375, in &lt;module&gt;
      app.searchData(debugInput)
   
  </code></pre>
  <p>Here is the code that I am trying to run:</p>
  <p>convToTfTensor Function inside of utilityTheory.py:</p>
  <pre><code>import tensorflow as tf
  import tensorflow 
  from tensorflow.keras import Sequential
  from tensorflow.keras.layers import Activation, Dense
  import numpy as np
  def convToNpArray(var):
      if var is not None:
          if var is tuple or str or int:
              newArray = np.array(var)
              return newArray
          else:
              raise ValueError(&quot;Error: variable is not type tuple, str, or int, please selelct one of these values.&quot;)
      else:
          raise ValueError(&quot;Error: variable is None, please change it's value.&quot;)
  def convToTfTensor(variable):
          if variable is not None:
              if variable is tuple or str or int:
                  newTensor = tf.Tensor(variable, 1, dtype=np.int32)
                  return newTensor
              else:
                  raise ValueError(&quot;Error: variable is not type tuple, str, or int, please select one of these values.&quot;)
          else:
              raise ValueError(&quot;Error: variable is None, please change it's value.&quot;)
  def getActivation(activation):
      if activation is not None:
          if activation == 'leakyRelu':
              pass
          elif activation == 'relu':
              pass
          elif activation == 'mae':
              pass
          elif activation == 'linear':
              pass
          elif activation == 'elu':
              pass
          elif activation == 'softmax':
              pass
          elif activation == 'sign':
              pass
          elif activation == 'selu':
              pass
      else:
          raise ValueError(&quot;Error: activation function is None, please select a value.&quot;)
  </code></pre>
  <p>createNewTheory class with the initializeTheory function inside of it, also appart of utilityTheory.py:</p>
  <pre><code>class createNewTheory(object):
      def __init__(self, prediction, activationSig, epsilon=1e-8, subClass=None):
          super().__init__()
          self.prediction = prediction
          self.subClass = subClass
          self.epsilon = epsilon
          self.activationSig = activationSig
          self.initalizeTheory()
          self.lossfilename = 'lossData.json'
          self.accuracyfilename = 'accuracyData.json'
      def initalizeTheory(self):
          self.X = self.prediction
          if self.subClass is not None:
              y = self.subClass
          if self.subClass is None:
              lengthMatrix = np.int32(([1], [2]))
              y = convToTfTensor(lengthMatrix)
          model = Sequential()
          model.add(Dense(4, activation=getActivation(self.activationSig), use_bias=True))
          model.add(Dense(1, activation=getActivation(self.activationSig), use_bias=True))
          adam = tf.keras.optimizers.Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=self.epsilon, amsgrad=False, name='Adam')
          model.compile(loss='sparse_catagorical_crossentropy', optimizer=adam, metrics=['binary_accuracy'])
  
          modelHistory = model.fit(self.X, y, epochs=2000, validation_data=(self.X, y))
  
          model.summary()
  
          self.lossHistory = modelHistory.history[&quot;loss&quot;]
          self.numpyLossHistory = convToNpArray(self.lossHistory)
          with open(self.lossfilename, 'w') as file:
              file.write(self.numpyLossHistory)
          binaryAccuracyHistory = modelHistory.history[&quot;binary_accuracy&quot;]
          numpyBinaryAccuracy = convToNpArray(binaryAccuracyHistory)
          with open(self.accuracyfilename, 'wb') as file:
              file.write(numpyBinaryAccuracy)
          print(np.mean(modelHistory.history[&quot;binary_accuracy&quot;]))
  
          self.result = model.predict(self.X).round()
          print(self.result) 
  </code></pre>
  <p>What could I be potentially missing here, any help would be greatly appretiated thank you!</p>