在我的主文件中,我有:
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)
我在 createsplit.py 文件中调用 create_training_data 函数,该文件是:
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
但是,运行原始文件会导致错误: NameError:全局名称' np'没有定义由于某种原因我不明白。我假设我以错误的方式导入函数,但我并不真正理解错误。
答案 0 :(得分:1)
我认为这个问题只是因为函数的错误调用而引发的。尝试
web_reg_save_param_regexp("ParamName=UserDetails",
"RegExp=\{\"name\"\:\"(\w+\s+\w+)\"\,\"id\"\:\"(\d+)\"\}",
SEARCH_FILTERS,
"Scope=Body",
"RequestUrl=*/onboarding/viewTaskTypes*",
"GROUP=1",
LAST);
web_url("viewTaskTypes", "URL=http://peguser.trials621.orangehrmlive.com/onboarding/viewTaskTypes",
"Resource=0",
"RecContentType=text/html", "Referer=http://peguser.trials621.orangehrmlive.com/onboarding/viewTaskTypes",
"Snapshot=t176.inf",
"Mode=HTTP",
LAST);
相反,它应该工作。