【发布时间】:2021-07-01 12:58:32
【问题描述】:
我有一个变量losses_all = [],我想将其转换为 np.array。我尝试使用代码这样做并收到以下错误:
# convert to numpy array
losses = np.array(losses_all)
# ERROR MESSAGE
RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.
我也试过了,但出现以下错误:
# using code from error message above
losses=losses_all.detach().numpy()
# NEW ERROR MESSAGE
AttributeError: 'list' object has no attribute 'detach'
还有其他方法可以将此变量转换为数组吗?
【问题讨论】: