失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Scipy教程 - python数值计算库

Scipy教程 - python数值计算库

时间:2021-12-15 06:37:45

相关推荐

Scipy教程 - python数值计算库

/pipisorry/article/details/39123171

Introduction to Scipy

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

下载及安装参考[linux和windows下安装python拓展包及requirement.txt安装类库]

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.clustervqhierarchyscipy.constantsscipy.fftpackscipy.integratescipy.interpolatescipy.ioarffharwell_boeingidlmatlabnetcdfwavfilescipy.linalgscipy.linalg.blasscipy.linalg.lapackscipy.linalg.interpolativescipy.miscscipy.ndimagescipy.odrscipy.optimizescipy.signalscipy.sparselinalgcsgraphscipy.spatialdistancescipy.specialscipy.statsdistributionsmstatsscipy.weave

[API - importing from Scipy]

皮皮blog

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 detailsis 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 understoodrules for what is and isn’t public in Pythonare:

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 aremodules 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 byimsave(and otherim*functions inscipy.misc). 【/questions/9298665/cannot-import-scipy-misc-imread】

2. You need to doimport scipy.miscorfrom scipy import misc.

[python模块导入及属性:import ]

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 functioncurve_fit(defined in scipy/optimize/minpack.py) should be imported like this:

from scipy import optimizeresult = optimize.curve_fit(...)

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

For examplethescipy.sparse.linalgmodule is public, and the functions it contains are not available in thescipy.sparsenamespace. 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 thatlomaxis a distribution if the second form is chosen:

# first formfrom scipy import statsstats.lomax(...)# second formfrom scipy.stats import distributionsdistributions.lomax(...)

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

皮皮blog

Scipy:高端科学计算

[/python//10/22/scipy/#scipyio]

from:/pipisorry/article/details/39123171

ref:scipy API及英文教程: /doc/scipy/reference/

如果觉得《Scipy教程 - python数值计算库》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。