TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first
这个错误表明您试图将一个位于 CUDA 设备上的张量转换为 NumPy 数组,但是 NumPy 不支持 CUDA 设备上的张量转换。
可以通过将张量移动到 CPU 上来解决此问题,然后再将其转换为 NumPy 数组。您可以使用 Tensor.cpu() 方法将张量移动到 CPU 上。
predict_triples = np.array(predict_triples, dtype=int)
⬇️⬇️⬇️
# 将张量移动到 CPU 上
predict_triples_cpu = predict_triples.cpu()
# 将张量转换为 Python 列表
predict_triples_list = predict_triples_cpu.tolist()
# 将 Python 列表转换为 NumPy 数组
predict_triples = np.array(predict_triples_list, dtype=int)
成功❗❗
o( ̄▽ ̄)ブ⭐⭐