我正在尝试从函数内部访问变量,它给了我一个错误,提示:
NameError: name 'perm_sample_1' is not defined
代码在这里:
def permutation_sample(data1,data2):
data = np.concatenate((data1,data2))
permuted_data = np.random.permutation(data)
perm_sample_1 = permuted_data[:len(data1)]
perm_sample_2 = permuted_data[len(data1):]
return perm_sample_1 , perm_sample_2
#return perm_sample_1.shape ,perm_sample_2.shape
def draw_perm_reps_func_diff(data1,data2,func,size=1):
perm_replicates = np.empty(size)
for i in range(size):
perm_sample_1 , perm_sample_2 = permutation_sample(data1,data2)
perm_replicates[i] = func(perm_sample_1) - func(perm_sample_2)
return perm_replicates
stats.ttest_ind_from_stats(mean1=np.mean(perm_sample_1), std1=np.std(perm_sample_1), nobs1=len(perm_sample_1),mean2=np.mean(perm_sample_2), std2=np.std(perm_sample_2), nobs2=len(perm_sample_2))
作为参数提供。