问题标签 [scipy]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
8 回答
32078 浏览

python - 使用 Python [摘要] 读取 wav 文件的最简单方法是什么?

我想使用 Python 访问一个 wav 文件并以允许我分析它的形式写入它的内容(比如说数组)。

  1. 我听说“audiolab”是一个合适的工具(它将numpy数组转换为wav,反之亦然)。
  2. 我已经安装了“audiolab”,但是 numpy 的版本有问题(我不能“从 numpy.testing 导入测试器”)。我有 1.1.1。numpy 的版本。
  3. 我在 numpy (1.4.0) 上安装了更新版本。但后来我得到了一组新的错误:

    Traceback(最近一次调用最后):文件“test.py”,第 7 行,在 import scikits.audiolab 文件“/usr/lib/python2.5/site-packages/scikits/audiolab/init .py ”,第 25 行,从 pysndfile 导入 formatinfo,sndfile 文件“/usr/lib/python2.5/site-packages/scikits/audiolab/pysndfile/init .py ”,第 1 行,从 _sndfile 导入 Sndfile,格式,available_file_formats,available_encodings 文件“numpy .pxd",第 30 行,在 scikits.audiolab.pysndfile._sndfile (scikits/audiolab/pysndfile/_sndfile.c:9632) ValueError: numpy.dtype does not seem to be the correct type object

  4. 我放弃了使用 audiolab 并认为我可以使用“wave”包来读取 wav 文件。我问了一个问题,但人们建议改用 scipy。好的,我决定专注于 scipy(我有 0.6.0. 版本)。

  5. 但是当我尝试执行以下操作时:

    从 scipy.io 导入 wavfile
    x = wavfile.read('/usr/share/sounds/purple/receive.wav')

我得到以下信息:

  1. 所以,我放弃了使用 scipy。我可以只使用wave包吗?我不需要太多。我只需要具有人类可读格式的 wav 文件内容,然后我会弄清楚如何处理它。
0 投票
5 回答
15687 浏览

python - Python 和 Scipy 的季节性调整

我希望使用 Python 对每月数据进行季节性调整。正如您从这些系列中看到的那样:www.emconfidential.com,数据中有很高的季节性成分。我想对此进行调整,以便更好地判断系列趋势是上升还是下降。有人知道如何使用 scipy 或其他 Python 库轻松做到这一点吗?

0 投票
2 回答
1687 浏览

numpy - Numpy:将一维索引转换为多维

尽管数组是多维的,但许多数组方法返回单个索引。例如:

对于二维,很容易找到最大元素的矩阵索引:

但是对于更多维度,它可能会变得烦人。给定一个(折叠)维度中的索引,Numpy/Scipy 是否有一种简单的方法来返回多个维度中的索引?谢谢。

0 投票
4 回答
10723 浏览

python - Python web hosting: Numpy, Matplotlib, Scientific Computing

I write scientific software in Numpy/Scipy/Matplotlib. Having developed applications on my home computer, I am now interested in writing simple web applications. Example: user uploads image or audio file, my program processes it using Numpy/Scipy, and output is displayed on the browser using Matplotlib, or perhaps the user can download a processed file.

I already pay for hosting that does have Python 2.4.3 installed, but no Numpy/Scipy. I don't have shell access via command line, either. Just drag-and-drop FTP. Pretty limited, but I can get simple Python/CGI scripts working.

Surprisingly, a web search revealed few suitable options for web hosting with these capabilities already built in. (Please guide me if I am wrong.) I am learning about the Google App Engine, but I still don't have a full understanding about its tools and limitations. What the web did tell me is that others have similar concerns.

Hoping for solutions, I thought I would ask these simple questions to the awesome SO community:

  1. Is there a simple way of installing numpy (or any third-party package/library) onto my already hosted space? I know the Python path on my hosted space, and I know the relevant Python/Numpy directories on my home computer. Can I simply copy files over and have it work? Both local and remote systems run Ubuntu.

  2. What hosting sites exist (either free or paid) which have Numpy/Matplotlib installed or, if not installed, the possibility of installing it? Are there any documented sites that you can reference with working applications, no matter how simple?

  3. Can Google App Engine help me in any way? Or is it totally for something else? Have you or others used it to write scientific applications in Python/Numpy? If so, could you reference them?

Thank you for your help.

EDIT: After the useful answers below, I bought the $20 plan at Slicehost, and I love it so far! (I first tried Amazon EC2. I must be stupid, but I just couldn't get it to work.) Setting up the Ubuntu server with Apache took mere hours (and I'm an Apache novice). It allows me to do exactly what I wanted with Python plus much more. I now have my own remote repository for version control, too. Thanks again!

EDIT 2: Nearly two years later, I tried Linode and EC2 (again). Linode is great. EC2 seemed easier this time around -- maybe it's just added experience, or maybe it's the improvements that Amazon made to the AWS management console. For those interested in Numpy/Scipy/Matplotlib/Audiolab, here is my Ubuntu cheat sheet whenever I launch an EC2 instance:

0 投票
4 回答
19433 浏览

python - 将刚性 ODE 与 Python 集成

我正在寻找一个可以在 Python 中集成僵硬 ODE 的好库。问题是,scipy 的 odeint有时会给我很好的解决方案,但初始条件的最轻微变化会导致它倒下并放弃。MATLAB 的刚性求解器(ode15s 和 ode23s)非常愉快地解决了同样的问题,但我不能使用它(即使是 Python,因为 MATLAB C API 的 Python 绑定都没有实现回调,我需要传递一个函数到 ODE 求解器)。我正在尝试 PyGSL,但它非常复杂。任何建议将不胜感激。

编辑:我在使用 PyGSL 时遇到的具体问题是选择正确的阶跃函数。其中有几个,但没有直接与 ode15s 或 ode23s 类似(bdf 公式和修改后的 Rosenbrock,如果有意义的话)。那么对于刚性系统来说,什么是好的阶跃函数呢?我必须对这个系统求解很长时间才能确保它达到稳态,而 GSL 求解器要么选择一个很小的时间步长,要么选择一个太大的时间步长。

0 投票
6 回答
47791 浏览

python - 从 numpy 数组列表创建 numpy 数组的 Pythonic 方法

我在循环中生成一维 numpy 数组的列表,然后将此列表转换为 2d numpy 数组。如果我提前知道项目的数量,我会预先分配一个 2d numpy 数组,但我不知道,因此我将所有内容都放在一个列表中。

模拟如下:

我的问题如下:

有没有更好的方法(性能方面)来完成收集顺序数值数据(在我的情况下为 numpy 数组)的任务,而不是将它们放在一个列表中,然后从中制作一个 numpy.array(我正在创建一个新的 obj 并复制数据)?在经过良好测试的模块中是否有可用的“可扩展”矩阵数据结构?

我的二维矩阵的典型大小在 100x10 和 5000x10 浮点数之间

编辑:在这个例子中,我使用的是地图,但在我的实际应用程序中,我有一个 for 循环

0 投票
1 回答
5165 浏览

python - 使用 scipy.io.savemat 将 python 变量保存到 .mat 文件

这是我的python代码。

但我收到一条错误消息

非常感谢您帮助解决问题。

维平 TS

0 投票
2 回答
32726 浏览

python - 将点分配给 bin

将数值分类到一定范围内的好方法是什么?例如,假设我有一个值列表,我想按它们的范围将它们放入 N 个 bin 中。现在,我做这样的事情:

其中 min_index 返回最小值的索引。这个想法是,您可以通过查看它与哪个 bin 的差异最小来找到该点所在的 bin。

但我认为这有奇怪的边缘情况。我正在寻找的是一个很好的垃圾箱表示,理想情况下是半开半开的垃圾箱(这样就无法将一个点分配给两个垃圾箱),即

使用 numpy/scipy 在 Python 中执行此操作的好方法是什么?我在这里只关心合并整数值。

非常感谢您的帮助。

0 投票
2 回答
1894 浏览

python - Mac 10.6 通用二进制 scipy:找不到 cephes/specfun "_aswfa_" 符号

当编译为 i386/x86_64 通用二进制文件并在我的 64 位 10.6.2 MacPro1,1 上执行时,我无法让 scipy 在 32 位模式下运行。

我的蟒蛇设置

在这个答案的帮助下,我构建了 python 2.6.4 的 32/64 位英特尔通用二进制文件,目的是使用arch命令在架构之间进行选择。(我设法使用 lipo 制作了一些我想要的库的通用二进制文件。)这一切都有效。然后,我根据hyperjeff 的文章中的说明安装了 scipy ,仅使用了更新的 numpy (1.4.0),并在安装 scipy 期间略过了将 numpy 移到一边的内容。

现在,据我所知,除了 scipy 之外的所有东西似乎都在工作,而且我确实可以使用arch -i386 pythonand在 32 位和 64 位模式之间进行选择arch -x86_64 python

错误

Scipy 在 32 位模式下抱怨:

尝试追踪问题

看起来 scipy.interpolate 导入了一个叫做 的东西_cephes,它寻找一个叫做的符号,_aswfa_但在 32 位模式下找不到它。浏览 scipy 的源码,我ASWFA在 specfun.f 中找到了一个子程序。唯一具有相似名称的 scipy 产品文件是 specfun.so,但它和 _cephes.so 似乎都是通用二进制文件:

哼哼。我被困住了。我可能会尝试但还没有弄清楚如何包括手动编译 specfun.so 的事情,不知何故。

我想所有 32 位机器的 scipy 都没有损坏,所以我猜我安装它的方式有问题,但我不知道是什么。

考虑到我相当独特的 (?) 设置,我真的不期待一个完整的答案,但如果有人有任何线索可以为我指明正确的方向,他们将不胜感激。

(编辑)解决问题的更多细节:

我正在使用 gfortran(来自 GCC 4.2.1 Apple Inc. build 5646 的 GNU Fortran)。

Python 2.6.4 或多或少是这样安装的:

Scipy 0.7.1 的安装与此处描述的差不多,但归结为一个简单的sudo python setup.py install.

如果nm按照 David Cournapeau 的建议查看带有 的 _cephes 库,确实会出现该符号在 i386 架构中未定义:

但是,我还不能解释它的缺席。

0 投票
2 回答
8263 浏览

python - 求三次 B 样条的长度

使用 scipy 的interpolate.splprep函数在 parameter 上得到一个参数样条u,但 的域u不是样条的线积分,它是输入坐标的分段线性连接。我试过integrate.splint了,但这只是给出了个人积分u。显然,我可以对一堆笛卡尔微分距离进行数值积分,但我想知道是否有封闭形式的方法来获取我忽略的样条线或样条线段(使用 scipy 或 numpy)的长度。

编辑:我正在寻找一种封闭形式的解决方案或一种非常快速的方法来收敛到机器精度的答案。我几乎放弃了数字求根方法,现在主要是在寻求封闭形式的答案。如果有人有集成椭圆函数的经验,或者可以指出一个好的资源(Wolfram 除外),那就太好了。

我将尝试 Maxima 来尝试获得我认为是样条线段的函数的不定积分:我在MathOverflow上交叉发布了这个