在cmd中查询numpy版本为1.22.4
但在vscode里运行时提示
发生异常: ImportError
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "D:\anaconda\envs\tensorflow\python.exe"
* The NumPy version is: "1.22.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
During handling of the above exception, another exception occurred:
File "E:\桌面1\yolo3-pytorch-master\utils\callbacks.py", line 4, in
import torch
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "D:\anaconda\envs\tensorflow\python.exe"
* The NumPy version is: "1.22.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
请问应该怎么解决?
通过截图分析如下:
参考博文Anaconda-用conda创建python虚拟环境
不知道你这个问题是否已经解决, 如果还没有解决的话:假设我们需要对两个向量a
和b
做加法。这里的向量即数学意义上的一维数组,随后我们将在第5章中学习如何用NumPy
数组表示矩阵。向量a
的取值为0~n
的整数的平方,例如n
取3
时,向量a
为0
、 1
或4
。向量b
的取值为0~n
的整数的立方,例如n
取3
时,向量b
为0
、 1
或8
。用纯Python代码应该怎么写呢?我们先想一想这个问题,随后再与等价的NumPy
代码进行比较。
(1) 纯Python代码:
def pythonsum(n):
a = range(n)
b = range(n)
c = []
for i in range(len(a)):
a[i] = i ** 2
b[i] = i ** 3
c.append(a[i] + b[i])
return c
(2) 使用NumPy
的代码:
def `NumPy`sum(n):
a = `NumPy`.arange(n) ** 2
b = `NumPy`.arange(n) ** 3
c = a + b
return c
注意, NumPy
sum()函数中没有使用for
循环。同时,我们使用NumPy
中的arange
函数来创建包含0~n 的整数的NumPy
数组。代码中的arange
函数前面有一个前缀NumPy
,表明该函数是从NumPy
模块导入的。
用NumPy
还是Python,得到的结果是一致的。不过,两者的输出结果在形式上有些差异。注意,NumPy
sum()
函数的输出不包含逗号。这是为什么呢?显然,我们使用的是NumPy
数组,而非Python自身的列表。