如果len(xi)> 0:TypeError:未确定对象MATPLOTLIB的len()

时间:2017-08-04 15:34:05

标签: python matplotlib

我有这个矩阵来绘制:

 1.0887e+00 -2.9071e+00  2.2645e+00  ...   2.2798e-01  6.1273e-01  2.9771e+00
 2.4369e-01 -1.5935e+00  1.9538e+00  ...  -8.5572e-01  1.2877e+00  7.0469e-01
 2.4409e-01 -1.4260e+00  1.0422e+00  ...  -9.8817e-01  8.8775e-01  4.3492e-01
                ...                   ⋱                   ...                
 1.5589e+00 -1.9514e+00  1.5131e+00  ...  -4.2420e-01  8.9567e-01  1.7066e+00
 9.5703e-01 -2.6811e+00  2.4477e+00  ...  -1.1068e-01  2.2908e+00  4.0621e+00
 8.5307e-01 -2.4534e+00  1.1746e+00  ...  -4.7006e-01  1.3858e+00  1.0349e+00
[torch.FloatTensor of size 37x512]

当我应用以下内容时:

import matplotlib.pylot as plt
plt.hist(conv0,bins=100)

我收到以下错误:

matplotlib/axes/_axes.py", line 6177, in hist
    if len(xi) > 0:
TypeError: len() of unsized object

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

您可能需要将矩阵作为numpy数组,而不是torch.FloatTensor。您可以尝试使用FloatTensor的{​​{3}}进行转换,例如:

plt.hist(conv0.numpy(), bins=100)