我对python很陌生。我做了一个列表(mean1
)假设输出是
2
3
4
5
的大小应该是4,在我看来,但是np。
1
1
1
1
我如何将那些分开的项目分组到一个组(数组)?我的目的是通过比较数字(2,3,4,5)和它的索引来找出一个最小值。(因此,最小值为2,index应为0)。这是我的代码:
for i in range(0,151):
mse=[]
for e in eval_indices:
#Define the evaluation set for the current fold
eval_set= z[e]
#exclude the upon parts indices from the
#whole array (similarly on the upon answers)
mask_eval = np.ones(z.shape[0], bool)
#Set indices of the eval set to false
mask_eval[e] = False
#Subset by the bool array:
train_set = z[mask_eval]
# Now find out w and mean value of MSEs of 10 evaluating subsets.
y=train_set[:,-1]
x=train_set[:,:-1]
I=np.identity(n=z.shape[1]-1, dtype=np.int8)
w=np.linalg.inv((i*I)+(np.transpose(x)@x))@np.transpose(x)@y
eval_y=eval_set[:,-1]
eval_x=eval_set[:,:-1]
mse_tst=1/(2*len(eval_set))*(np.transpose(eval_y-(eval_x@w))@(eval_y-(eval_x@w)))
mse.append(mse_tst)
mean1=np.mean(mse)
mean1=np.array(mean1)
print(np.size(mean1))
如果我理解正确的话,您需要一个单独的数组:
mse = []
means = []
for e in eval_indices:
...
mean1=np.mean(mse)
means.append(mean1)
然后你会有一个所有方法的列表。