title: Python TypeError: op needs to be operation [0 0 0]
body: <p>I am trying to run a neural network using Tensorflow using Visual Studio Code but when I run the program I encounter a TypeError in my conv_x_to_var function. I have tried looking for possible solutions for this specific problem on StackOverflow but so far I have not found any possible solutions to my problem, besides another question that I had posted in December of last year. I have also tried to change my code to just return the function without the tensor but alas that doesn't work as well, as that solution just gives me another error.
  Here is the <code>TypeError</code> I am receiving when I run my program:</p>
  <pre><code>Exception has occurred: TypeError
  op needs to be an Operation: [0 0 0]
    File &quot;C:\Users\trevo\OneDrive\Desktop\vegaai-master\tensor_net\neuralnet.py&quot;, line 65, in conv_x_to_var
      return Variable(tf.Tensor(np.array(x), (len(x), len(x)), np.float64))
    File &quot;C:\Users\trevo\OneDrive\Desktop\vegaai-master\tensor_net\neuralnet.py&quot;, line 85, in InitializeNeuralNet
      origin = self.conv_x_to_var([0,0,0])
    File &quot;C:\Users\trevo\OneDrive\Desktop\vegaai-master\tensor_net\neuralnet.py&quot;, line 63, in __init__
      self.InitializeNeuralNet()
    File &quot;C:\Users\trevo\OneDrive\Desktop\vegaai-master\tensor_net\neuralnet.py&quot;, line 132, in &lt;module&gt;
      net = NetMain()
  </code></pre>
  <p>Here is my Python code in my <code>neuralnet.py</code> script:</p>
  <pre><code>from pickletools import optimize
  from re import X
  from turtle import shape
  from sklearn import metrics
  import tensorflow as tf
  import numpy as np 
  from tensorflow.python.keras import layers
  from tensorflow.python.keras.layers import Activation, Dense, Dropout
  from tensorflow.python.ops.variables import Variable
  from keras.models import Sequential
  import matplotlib
  from sklearn.model_selection import train_test_split
  from tensorflow.python import keras
  import matplotlib.pyplot as plt
  from tensorflow.python.ops.linalg_ops import norm
  import wolframalpha as wolf
  from os import path, read
  import autograd
  import sys
  import pandas as pd
  from tqdm import tqdm, trange
  
  class NetMain():
      def __init__(self):
          self.InitializeNeuralNet()
      def conv_x_to_var(self, x):
          return Variable(tf.Tensor(np.array(x), (len(x), len(x)), np.float64))
      def conv_y_to_var(self, y):
          return Variable(tf.Tensor(np.array(y), (len(y), len(y)), np.float64))
      def conv_to_numpy(self, n):
          return n.data.cpu().numpy()
      def InitializeNeuralNet(self, activation='relu', loss='mean_sqaured_error', optimizer='sgd', metrics=['accuracy'], epochs=300, Nsamples=20000, max_Nfeatures=100):       
          #vegaMain = VegaAiMain()
          xs = []
          ys = []
          for i in trange(Nsamples):
              Nfeatures = np.random.randint(max_Nfeatures-40) + 40
  
              interX = np.random.rand(Nfeatures, 3) * 50 - 50 * np.random.rand(3)
  
              X = np.zeros((Nfeatures, Nfeatures, 6))
              X[:,:,:3] = np.expand_dims(interX, 1)
              X[:,:,3:] = np.expand_dims(interX, 0)
              X = X.reshape(-1,6)
              X = np.mgrid[1:2:len(X)]
  
              origin = self.conv_x_to_var([0,0,0])
  
              x1 = self.conv_x_to_var(X[:,:3]) - origin
              x2 = self.conv_x_to_var(X[:,3:]) - origin
              r1 = norm(x1)
              r2 = norm(x2)
  
              z = 1 / r1 / r2
              z = np.sum(z) * 1e4
              
              y = X.conv_to_numpy(z)
  
              xs.append(np.mean(X, 0))
              ys.append(y / (len(X)))
          
          
          dataset = train_test_split(xs, ys, train_size=0.8)
  
          (x_train, y_train), (x_test, y_test) = X.dataFrameRead
  
          model = Sequential()
          model.add(Dense(units=400, input_dim=6))
          model.add(Activation(activation))
          model.add(Dense(units=200))
          model.add(Activation(activation))
          model.add(Dense(units=100))
          model.add(Dropout(0.2))
          model.add(Dense(units=50))
          model.add(Activation(activation))
          model.add(Dropout(0.2))
          model.add(Dense(units=25))
          model.add(Activation(activation))
          model.add(Dense(units=3))
  
          sgd = tf.keras.optimizers.SGD(learning_rate=0.001, momentum=0.9, nesterov=True)
          print(model.get_weights())
          model.summary()
          model.compile(loss=loss, optimizer=optimizer, metrics=metrics)
  
          model.fit(np.array(x_train), np.array(y_train), epochs=100, batch_size=50, nesterov=True)
  
          loss_data = model.evaluate(np.array(x_test), np.array(y_test), batch_size=100)
  
          classes = model.predict(np.array(x_test), batch_size=1)
  
          print([classes[:10]])
          print(y_test[:10])
  net = NetMain()
  </code></pre>
  <p>What exactly can I do to fix this code? thank you!</p>