python /赛通 : Using SciPy with Cython

标签 python c statistics scipy cython

Cython 教程展示了一个很好的示例,说明如何将 Numpy 与 Cython 结合使用。但是,我有使用 scipy.stats 包的代码,在尝试编译代码时,出现如下错误:

dvi.pyx:7:8: 'scipy.stats.pxd' not found

我担心 Cython(?)不支持 scipy。有人可以评论在 Cython 中使用 scipy 或指出一些资源/教程的方向吗?谢谢!

最佳答案

所以我在 Cython Google Group ( https://groups.google.com/forum/?fromgroups#!searchin/cython-users/using$20scipy/cython-users/CF9GqYN1aPU/WKC-N9c6zpgJ ) 上找到了代码

将以下内容显示为导入:

import pylab as PL
from scipy import integrate
from scipy import optimize
from scipy.integrate import odeint

import numpy as np
cimport numpy as np
cimport cython

这让我有信心使用 SciPy 进行编译。添加 cimport cython 语句时,我收到以下编译错误:

dvi.c:237:31: error: numpy/arrayobject.h: No such file or directory
dvi.c:238:31: error: numpy/ufuncobject.h: No such file or directory

似乎存在路径或目录问题。事实上我是对的,这个网站上有一个帖子(My Cython code parses into C, but doesn't compile. First time trying to use external C code)

解决方案是将以下内容添加到我的 setup.py 文件中:

import numpy 
...
Extension(..., include_dirs = [numpy.get_include(), ... ] )

W00t!

关于 python /赛通 : Using SciPy with Cython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11680055/

相关文章:

python - 如何在不使用numpy或tensorflow中的任何循环的情况下获取矩阵行?

c++ - C/C++涉及2个进程时如何使用fake function framework?

algorithm - 继续整数数组的模式

rss - 我如何知道有多少人订阅了我提供的 RSS 提要?

python - python读取多个json

python - 组合框中的 map 数据与超过 256 个项目相关

python - Python-对2D数组中的每个元素执行操作并将其存储在新的2D数组中

c - 标准输入上最受欢迎的字符

将 C99 代码转换为 C89

r - 添加误差线以在R中的图上显示标准偏差