【问题标题】:Issue plotting a simple tensor with Torch使用 Torch 绘制简单张量的问题
【发布时间】:2021-10-27 15:57:23
【问题描述】:

刚开始使用 Pyorch,我正在尝试使用 Matplotlib 将一个非常简单的一维数组张量绘制到直方图上。

 torch.manual_seed(8436) 
 a = torch.Tensor(1000) 

 a.normal_(0, 2.) #This will fill our array with a normal distribution
 plt.hist(a);

However, the result is strange...,只是由一堆垂直的彩色线条组成。

The result I am supposed to get, which I do when entering:

plt.hist(a.numpy())

是正常的直方图。

提前感谢您的帮助!

【问题讨论】:

    标签: python matplotlib plot pytorch tensor


    【解决方案1】:

    好吧,在我看来,here 是原因:

    cbook._reshape_2D 用于预处理进入 plt.hist 的数据。在 3.4.3 中,它返回一个数组列表,每个数组只有一个元素,这显然会产生上面的错误图像。

    然而,在 3.2.2 中,它返回一个包含一个一维数组的列表,基本上是我们提供的张量的 NumPy 版本。这个是按预期绘制的。

    我降级了软件包并且它工作正常。有兴趣了解其他解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-02
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      • 2016-12-23
      • 2023-04-02
      相关资源
      最近更新 更多