from collections import defaultdict
#初始化一个列表型的变量,变量名为“result”
results = defaultdict(list)
for epoch in range(args.epochs):
...
results[‘loss‘].append(loss.item())
results[‘val_loss‘].append(val_loss.item())
np.ravel(list) #去掉嵌套的list
原文:https://www.cnblogs.com/amilychensblog/p/14730259.html