1

In my master file I have:

import matplotlib.pyplot as plt
import seaborn
import numpy as np
import time

import sys
sys.path.append("C:/.../python check/createsplit")
import createsplit

data='MJexample'
X,Y,N,Ntr=create_training_data(data)

where I am calling create_training_data function from createsplit.py file which is:

import numpy as np
import scipy.io

def create_training_data(data_type):
     """
     creates training data
     """
     if data_type=='MJexample':
         N=300
         Ntr = 150
         X=np.linspace(0,1,N)
         X = np.array([X,X*X,np.linspace(5,10,N),np.sin(X),np.cos(X),np.sin(X)*np.cos(X)]).T

         fac=40
         Y=np.array([np.sin(fac*x)*np.cos(fac*x**2) for x in X[:,0]])[:,None]

         _X=X
         _Y=Y
         return _X,_Y,N,Ntr

However running my original file results in error: NameError: global name 'np' is not defined for some reason I do not understand. I assume I am importing the functions in a wrong way but I don't really understand what would be wrong.

1
  • 1
    You want X,Y,N,Ntr=createsplit.create_training_data(data). Commented Jun 6, 2017 at 8:06

1 Answer 1

1

I think this issue raises just because of a wrong call of the function. Try

X, Y, N, Ntr = createsplit.create_training_data(data)

instead, and it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.