龙空技术网

乘风破浪的你!这20个Python库用起来倍儿有面子(下)

python小白社区 543

前言:

此时大家对“pythonmpi”都比较关注,看官们都想要知道一些“pythonmpi”的相关内容。那么小编在网络上收集了一些关于“pythonmpi””的相关内容,希望同学们能喜欢,各位老铁们一起来学习一下吧!

上面介绍了这些别致的用起来会让你不仅效率高,而且倍儿有面子的Python库乘风破浪的你!这20个Python库用起来倍儿有面子(上) 。下面继续介绍其余的。

11. NetworkX

NetworkX是用于研究图的库,可帮助您创建,操纵和研究复杂网络的结构,动力学和功能。

>>> import networkx as nx>>> G = nx.Graph()>>> G.add_edge('A', 'B', weight=4)>>> G.add_edge('B', 'D', weight=2)>>> G.add_edge('A', 'C', weight=3)>>> G.add_edge('C', 'D', weight=4)>>> nx.shortest_path(G, 'A', 'D', weight='weight')['A', 'B', 'D']
12. Nilearn

Nilearn是一个Python模块,用于快速方便地对神经影像数据进行统计学习。

该库使在神经影像数据上使用许多高级机器学习,模式识别和多元统计技术变得容易,例如MVPA(多体素模式分析),解码,预测建模,功能连接,脑部细胞分裂或连接组等应用。

from nilearn import imagesmooth_anat_img = image.smooth_img(MNI152_FILE_PATH, fwhm=3)# While we are giving a file name as input, the function returns# an in-memory object:smooth_anat_imgOut:<nibabel.nifti1.Nifti1Image object at 0x7f8755631510>This is an in-memory object. We can pass it to nilearn function, for instance to look at itplotting.plot_img(smooth_anat_img)
13. NumPy

NumPy是使用Python进行科学计算的基本软件包,它增加了对大型多维数组和矩阵的支持,以及对这些数组进行操作的大型高级数学函数库。

>>> np.zeros((3, 4))array([[0., 0., 0., 0.],       [0., 0., 0., 0.],       [0., 0., 0., 0.]])>>> np.ones( (2,3,4), dtype=np.int16 )                # dtype can also be specifiedarray([[[1, 1, 1, 1],        [1, 1, 1, 1],        [1, 1, 1, 1]],       [[1, 1, 1, 1],        [1, 1, 1, 1],        [1, 1, 1, 1]]], dtype=int16)>>> np.empty( (2,3) )                                 # uninitializedarray([[  3.73603959e-262,   6.02658058e-154,   6.55490914e-260],  # may vary       [  5.30498948e-313,   3.14673309e-307,   1.00000000e+000]])
14.Pandas熊猫

Pandas是一个用于数据处理和分析的库,提供用于处理数字表和时间序列的数据结构和操作。

In [2]: import pandas as pdObject creationSee the Data Structure Intro section.Creating a Series by passing a list of values, letting pandas create a default integer index:In [3]: s = pd.Series([1, 3, 5, np.nan, 6, 8])In [4]: sOut[4]: 0    1.01    3.02    5.03    NaN4    6.05    8.0dtype: float64Creating a DataFrame by passing a NumPy array, with a datetime index and labeled columns:In [5]: dates = pd.date_range('20130101', periods=6)In [6]: datesOut[6]: DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',               '2013-01-05', '2013-01-06'],              dtype='datetime64[ns]', freq='D')In [7]: df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))In [8]: dfOut[8]:                    A         B         C         D2013-01-01  0.469112 -0.282863 -1.509059 -1.1356322013-01-02  1.212112 -0.173215  0.119209 -1.0442362013-01-03 -0.861849 -2.104569 -0.494929  1.0718042013-01-04  0.721555 -0.706771 -1.039575  0.2718602013-01-05 -0.424972  0.567020  0.276232 -1.0874012013-01-06 -0.673690  0.113648 -1.478427  0.524988
15. Pipenv

Pipenv是一种旨在将所有包装领域的精华带入Python世界的工具。

它会自动为您的项目创建和管理virtualenv,并在您安装或卸载软件包时从Pipfile中添加或删除软件包。

Pipenv的主要目的是为应用程序的用户和开发人员提供一种简单的方法来设置工作环境。

Pipenv

16.PsychoPy精神病学

PsychoPy是用于生成神经科学和实验心理学实验的软件包。

它旨在允许对各种神经科学,心理学和心理物理实验进行刺激表示和数据收集。

17. PyTorch

PyTorch是用于快速,灵活实验的深度学习框架。

该软件包提供了两个高级功能:具有强大GPU加速功能的Tensor计算和基于磁带的autodiff系统构建的深度神经网络。

它既可以代替numpy来使用GPU的功能,也可以用作提供最大灵活性和速度的深度学习研究平台。

# -*- coding: utf-8 -*-import torchdtype = torch.floatdevice = torch.device("cpu")# device = torch.device("cuda:0") # Uncomment this to run on GPU# N is batch size; D_in is input dimension;# H is hidden dimension; D_out is output dimension.N, D_in, H, D_out = 64, 1000, 100, 10# Create random input and output datax = torch.randn(N, D_in, device=device, dtype=dtype)y = torch.randn(N, D_out, device=device, dtype=dtype)# Randomly initialize weightsw1 = torch.randn(D_in, H, device=device, dtype=dtype)w2 = torch.randn(H, D_out, device=device, dtype=dtype)learning_rate = 1e-6for t in range(500):    # Forward pass: compute predicted y    h = x.mm(w1)    h_relu = h.clamp(min=0)    y_pred = h_relu.mm(w2)    # Compute and print loss    loss = (y_pred - y).pow(2).sum().item()    if t % 100 == 99:        print(t, loss)    # Backprop to compute gradients of w1 and w2 with respect to loss    grad_y_pred = 2.0 * (y_pred - y)    grad_w2 = h_relu.t().mm(grad_y_pred)    grad_h_relu = grad_y_pred.mm(w2.t())    grad_h = grad_h_relu.clone()    grad_h[h < 0] = 0    grad_w1 = x.t().mm(grad_h)    # Update weights using gradient descent    w1 -= learning_rate * grad_w1    w2 -= learning_rate * grad_w2
18. SQLAlchemy

SQLAlchemy是一个开源SQL工具包和对象关系映射器,为应用程序开发人员提供了SQL的全部功能和灵活性。它提供了一整套著名的企业级持久性模式,旨在实现高效和高性能的数据库访问,并被适配为简单的Pythonic域语言。

该库的主要目标是改变查询数据库的SQL方式。

该库的主要目标是改变查询数据库的SQL方式。

19. SageMath

SageMath是一个数学软件系统,其功能涵盖了数学的多个方面,包括代数,组合数学,数值数学,数论和微积分。

它使用Python支持过程,功能和面向对象的构造。

sage: f = 1 - sin(x)^2sage: f-sin(x)^2 + 1sage: unicode_art(f)  # pretty printing       21 - sin (x)sage: f.simplify_trig()cos(x)^2sage: f(x=pi/2)0sage: f(x=pi/3)1/4sage: integrate(f, x).simplify_trig()1/2*sin(x)*cos(x) + 1/2*xsage: unicode_art(integrate(f, x).simplify_trig())x   sin(x)⋅cos(x)─ + ─────────────2         2sage: f.differentiate(2).substitute({x: 3/pi})2*sin(3/pi)^2 - 2*cos(3/pi)^2sage: unicode_art(f.differentiate(2).substitute({x: 3/pi}))       2⎛3⎞        2⎛3⎞- 2⋅cos ⎜─⎟ + 2⋅sin ⎜─⎟        ⎝π⎠         ⎝π⎠
20. ScientificPython

ScientificPython是用于科学计算的模块的集合。

它包含对几何,数学函数,统计,物理单位,IO,可视化和并行化的支持。ScientificPython是可用于科学计算的Python模块的集合。在这个集合中,您将找到涵盖基本几何(向量,张量,变换,向量和张量字段),四元数,自动导数,(线性)插值,多项式,基本统计量,非线性最小二乘拟合,单位计算,Fortran-兼容的文本格式,通过VRML进行3D可视化,以及两个用于简单线条图和3D线框模型的Tk小部件。还具有与netCDF库(便携式结构化二进制文件),MPI(消息传递接口,基于消息的并行编程)和BSPlib(批量同步并行编程)的接口。

小结

有这么多优秀的Python包和工具可供探索,您很有可能知道一些令人兴奋的Python库,它们都属于此列表。另外,您认为还有应该添加的库吗?欢迎在下面的评论部分中建议与您相关的任何其他Python软件。稍后的文章中可能会加入你的建议。

标签: #pythonmpi