RuntimeError: Numpy is not available


RuntimeError Traceback (most recent call last)
Cell In[21], line 1
----> 1 d2l.show_heatmaps(attention.attention_weights.reshape((1, 1, 2, 10)),
2 xlabel=‘Keys’, ylabel=‘Queries’)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/d2l/torch.py:1146, in show_heatmaps(matrices, xlabel, ylabel, titles, figsize, cmap)
1144 for i, (row_axes, row_matrices) in enumerate(zip(axes, matrices)):
1145 for j, (ax, matrix) in enumerate(zip(row_axes, row_matrices)):
-> 1146 pcm = ax.imshow(d2l.numpy(matrix), cmap=cmap)
1147 if i == num_rows - 1:
1148 ax.set_xlabel(xlabel)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/d2l/torch.py:2739, in (x, *args, **kwargs)
2737 abs = torch.abs
2738 eye = torch.eye
-> 2739 numpy = lambda x, *args, **kwargs: x.detach().numpy(*args, **kwargs)
2740 size = lambda x, *args, **kwargs: x.numel(*args, **kwargs)
2741 reshape = lambda x, *args, **kwargs: x.reshape(*args, **kwargs)

RuntimeError: Numpy is not available
/root/anaconda3/envs/LLM/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: MatplotlibDeprecationWarning: savefig() got unexpected keyword argument “facecolor” which is no longer supported as of 3.3 and will become an error two minor releases later
fig.canvas.print_figure(bytes_io, **kw)
/root/anaconda3/envs/LLM/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: MatplotlibDeprecationWarning: savefig() got unexpected keyword argument “edgecolor” which is no longer supported as of 3.3 and will become an error two minor releases later
fig.canvas.print_figure(bytes_io, **kw)
/root/anaconda3/envs/LLM/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: MatplotlibDeprecationWarning: savefig() got unexpected keyword argument “orientation” which is no longer supported as of 3.3 and will become an error two minor releases later
fig.canvas.print_figure(bytes_io, **kw)

解决:torch和numpy版本不匹配:如果是最新版torch,则需要适配最新版numpy,我的是2.0.1cu118的torch,使用最新numpy即可解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
"RuntimeError: numpy is not available"是一个常见的错误消息,在使用Python中的某些程序或库时可能会出现。它表示你的程序试图导入或使用NumPy库,但是没有找到已安装的NumPy库。 NumPy是一个用于进行科学计算和数组操作的Python库。它提供了许多用于处理大型多维数组和矩阵的功能,以及与这些数组和矩阵相关的数学运算。 出现"RuntimeError: numpy is not available"错误的常见原因有: 1. 未安装NumPy库:首先,请确保你已经正确地安装了NumPy库。可以使用pip命令(如pip install numpy)来安装NumPy。如果你使用的是Anaconda环境,可以使用conda命令(如conda install numpy)来安装。 2. NumPy版本不兼容:有时,你可能已经安装了NumPy,但版本与你的程序或其他库不兼容。你可以尝试升级NumPy版本或检查应用程序或库的兼容性要求。 3. 环境变量设置错误:如果已经安装了NumPy,但仍然出现这个错误,有可能是因为环境变量设置不正确。你可以检查你的Python环境变量和路径设置,并确保它们指向正确的NumPy安装位置。 4. 缺失依赖库:NumPy依赖于一些其他的库或组件,例如SciPy等。如果你缺少这些依赖库,也可能导致"RuntimeError: numpy is not available"错误。你可以安装这些依赖库来解决此问题。 综上所述,当你遇到"RuntimeError: numpy is not available"错误时,首先请检查NumPy库的安装情况。如果已经安装,并确保环境变量设置正确,但仍然出现错误,可能需要考虑升级NumPy版本或检查其他依赖库。在解决这个问题之后,你的程序应该能够正常使用NumPy库了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

irrationality

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值