这个错误通常是由于尝试对一个0维张量进行索引操作而引起的。在这种情况下,你可以使用tensor.item()方法将0维张量转换为一个数值。

根据你提供的代码,可能的原因是w.data.squeeze()[0]b.data.squeeze()[0]中的某个张量是0维的。你可以尝试使用tensor.item()来解决这个问题,如下所示:

print(w.data.squeeze().item(), b.data.squeeze().item())

这样,如果wb是0维张量,它们将被转换为数值并打印出来。

jupyter中 printwdatasqueeze0 bdatasqueeze0出现IndexError invalid index of a 0-dim tensor Use tensoritem in Python or tensoritemT in C++ to convert a 0-dim tensor to a number 的错误

原文地址: https://www.cveoy.top/t/topic/hHuQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录