御丽诗妃:这20个Python库用起来倍儿有面子

御丽诗妃:本文来源于网络,著作权归宿原作者。

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

原创 python小白社区 2020-08-13 09:52:09

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

11. NetworkX

http://networkx.github.io/

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

 

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

http://nilearn.github.io/

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

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

 

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

from nilearn import image
smooth_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_img
Out:

<nibabel.nifti1.Nifti1Image object at 0x7f8755631510>
This is an in-memory object. We can pass it to nilearn function, for instance to look at it

plotting.plot_img(smooth_anat_img)

13. NumPy

http://www.numpy.org/

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 specified
array([[[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) )                                 # uninitialized
array([[  3.73603959e-262,   6.02658058e-154,   6.55490914e-260],  # may vary
       [  5.30498948e-313,   3.14673309e-307,   1.00000000e+000]])

14.Pandas熊猫

http://pandas.pydata.org/

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

In [2]: import pandas as pd
Object creation
See 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]: s
Out[4]: 
0    1.0
1    3.0
2    5.0
3    NaN
4    6.0
5    8.0
dtype: float64
Creating 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]: dates
Out[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]: df
Out[8]: 
                   A         B         C         D
2013-01-01  0.469112 -0.282863 -1.509059 -1.135632
2013-01-02  1.212112 -0.173215  0.119209 -1.044236
2013-01-03 -0.861849 -2.104569 -0.494929  1.071804
2013-01-04  0.721555 -0.706771 -1.039575  0.271860
2013-01-05 -0.424972  0.567020  0.276232 -1.087401
2013-01-06 -0.673690  0.113648 -1.478427  0.524988

15. Pipenv

https://github.com/pypa/pipenv

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

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

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

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

Pipenv

16.PsychoPy精神病学

http://www.psychopy.org/

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

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

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

 

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

 

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

 

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

 

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

 

 

17. PyTorch

https://pytorch.org/

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

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

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

# -*- coding: utf-8 -*-

import torch


dtype = torch.float
device = 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 data
x = torch.randn(N, D_in, device=device, dtype=dtype)
y = torch.randn(N, D_out, device=device, dtype=dtype)

# Randomly initialize weights
w1 = torch.randn(D_in, H, device=device, dtype=dtype)
w2 = torch.randn(H, D_out, device=device, dtype=dtype)

learning_rate = 1e-6
for 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

http://www.sqlalchemy.org/

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

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

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

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

19. SageMath

http://www.sagemath.org/

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

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

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

20. ScientificPython

http://dirac.cnrs-orleans.fr/ScientificPython/

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

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章