python数值计算库教程_Scipy教程 - python数值计算库

Introduction to Scipy

SciPy函数库在NumPy库的基础上增加了众多的数学、科学以及工程计算中常用的库函数。例如线性代数、常微分方程数值求解、信号处理、图像处理、稀疏矩阵等等,涉及的领域众多。可以进行插值处理、信号滤波以及用C语言加速计算。

scipy API definition

Every submodule listed below is public.That means that these submodules are unlikely to be renamed or changed in an incompatible way, and if that is necessary a deprecation warning will be raised for one Scipy release before the change is made.

scipy.cluster

vq

hierarchy

scipy.constants

scipy.fftpack

scipy.integrate

scipy.interpolate

scipy.io

arff

harwell_boeing

idl

matlab

netcdf

wavfile

scipy.linalg

scipy.linalg.blas

scipy.linalg.lapack

scipy.linalg.interpolative

scipy.misc

scipy.ndimage

scipy.odr

scipy.optimize

scipy.signal

scipy.sparse

linalg

csgraph

scipy.spatial

distance

scipy.special

scipy.stats

distributions

mstats

scipy.weave

Scipy中引入包的规则

'scipy' is actually a collection of subpackages.  The subpackages are not imported by executing 'import scipy'.  You'll have to explicitly import the scipy.spatial package with 'import scipy.spatial'.

其实主要是__init__.py中没有from . import subpackages,自己修改一下就好了,不过它本身没这么加肯定有它的原因,lz暂时还没搞清楚。

[scipy-ref-0.14.0-p933]

如果直接使用scipy调用会出现以下错误

...

scipy.misc.imsave(filename, numpy.kron(doc, zoom))...

AttributeError: 'module' object has no attribute 'misc'

发生错误的原因

Most possibly because scipy is a library (package) that contains modules and to import a specific module from the scipy library, you need to specify it and import the module itself. As it's a separate module (sub-package), once you import it, it's attributes are available to you by using the regular scipy.module.attribute.

The modules inside scipy aren't accessible as attributes of the base scipy package.

对引入格式的说明

In Python the distinction between what is the public API of a library and what areprivate implementation details is not always clear. Unlike in other languages like Java, it is possible in Python to access “private” function or objects. Occasionally this may be convenient, but be aware that if you do so your code may break without warning in future releases.

Some widely understood rules for what is and isn’t public in Python are:

Methods / functions / classes and module attributes whose names begin with a leading underscore are private.

If a class name begins with a leading underscore none of its members are public, whether or not they begin with a leading underscore.

If a module name in a package begins with a leading underscore none of its members are public, whether or not they begin with a leading underscore.

If a module or package defines __all__ that authoritatively defines the public interface.

If a module or package doesn’t define __all__ then all names that don’t start with a leading underscore are public.

Note:Reading the above guidelines one could draw the conclusion that every private module or object starts with an underscore. This is not the case; the presence of underscores do mark something as private, but the absence of underscores do not mark something as public.

In Scipy there are modules whose names don’t start with an underscore, but that should be considered private. To clarify which modules these are we define below what the public API is for Scipy, and give some recommendations for how to import modules/functions/objects from Scipy.

解决

1. You might need to install PIL or Pillow.

PIL is required by imsave (and other im* functions in scipy.misc).  【http://stackoverflow.com/questions/9298665/cannot-import-scipy-misc-imread】

2. You need to do import scipy.misc orfrom scipy import misc.

Guidelines for importing functions from Scipy 从scipy中引入包

The scipy namespace itself only contains functions imported from numpy. These functions still exist for backwards compatibility, but should be imported from numpy directly.

Everything in the namespaces of scipy submodules is public. In general, it is recommended to import functions from submodule namespaces.

For example,the function curve_fit (defined in scipy/optimize/minpack.py) should be imported like this:

from scipy import optimize

result = optimize.curve_fit(...)

In some cases, the public API is one level deeper.

For example the scipy.sparse.linalg module is public, and the functions it contains are not available in thescipy.sparse namespace. Sometimes it may result in more easily understandable code if functions are imported from one level deeper.

For example, in the following it is immediately clear thatlomax is a distribution if the second form is chosen:

# first form

from scipy import stats

stats.lomax(...)

# second form

from scipy.stats import distributions

distributions.lomax(...)

In that case the second form can be chosen, if it is documented in the next section that the submodule in question is public.

Scipy:高端科学计算

http://blog.csdn.net/pipisorry/article/details/39123171

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值