御麗詩妃:這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(批量同步並行編程)的接口。

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