Open stevexxs opened 5 years ago
As suggested here you could create a python file with all your global variables and then import them, e.g.:
### [FILE NAME = globalvars.py] ###
global x_train, y_train, x_test, y_test
x_train = ...
then in the file where you define your data()
function:
import globalvars as gv
def data():
x_train = gv.x_train
y_train = gv.y_train
x_test = gv.x_test
y_test = gv.y_test
return x_train, y_train, x_test, y_test
of course it's not the cleanest or neat in any way, but it will solve your problem.
I know that data function is a must, but how can I return global variable inside data function ?
like, X_train, y_train = .. X_test, y_test = ... def data(): return X_train, X_test, y_train, y_test
but when run optim.minimize(), the below NameError happened. NameError: name 'X_train' is not defined
Is there anyone tell me how to fix this ?