Scipy基础 绘制函数expit的图像

  •        Python : 3.8.11
  •       scipy : 1.6.2
  •          OS : Ubuntu Kylin 20.04
  •       Conda : 4.10.1
  •    jupyter lab : 3.1.4

代码示例

import scipy.special
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
复制代码
# number = 100
x = np.linspace(-10,10,100)
x

array([-10.        ,  -9.7979798 ,  -9.5959596 ,  -9.39393939,
        -9.19191919,  -8.98989899,  -8.78787879,  -8.58585859,
        -8.38383838,  -8.18181818,  -7.97979798,  -7.77777778,
        -7.57575758,  -7.37373737,  -7.17171717,  -6.96969697,
        -6.76767677,  -6.56565657,  -6.36363636,  -6.16161616,
        -5.95959596,  -5.75757576,  -5.55555556,  -5.35353535,
        -5.15151515,  -4.94949495,  -4.74747475,  -4.54545455,
        -4.34343434,  -4.14141414,  -3.93939394,  -3.73737374,
        -3.53535354,  -3.33333333,  -3.13131313,  -2.92929293,
        -2.72727273,  -2.52525253,  -2.32323232,  -2.12121212,
        -1.91919192,  -1.71717172,  -1.51515152,  -1.31313131,
        -1.11111111,  -0.90909091,  -0.70707071,  -0.50505051,
        -0.3030303 ,  -0.1010101 ,   0.1010101 ,   0.3030303 ,
         0.50505051,   0.70707071,   0.90909091,   1.11111111,
         1.31313131,   1.51515152,   1.71717172,   1.91919192,
         2.12121212,   2.32323232,   2.52525253,   2.72727273,
         2.92929293,   3.13131313,   3.33333333,   3.53535354,
         3.73737374,   3.93939394,   4.14141414,   4.34343434,
         4.54545455,   4.74747475,   4.94949495,   5.15151515,
         5.35353535,   5.55555556,   5.75757576,   5.95959596,
         6.16161616,   6.36363636,   6.56565657,   6.76767677,
         6.96969697,   7.17171717,   7.37373737,   7.57575758,
         7.77777778,   7.97979798,   8.18181818,   8.38383838,
         8.58585859,   8.78787879,   8.98989899,   9.19191919,
         9.39393939,   9.5959596 ,   9.7979798 ,  10.        ])
复制代码
y = scipy.special.expit(x)
y

array([4.53978687e-05, 5.55606489e-05, 6.79983174e-05, 8.32200197e-05,
       1.01848815e-04, 1.24647146e-04, 1.52547986e-04, 1.86692945e-04,
       2.28478855e-04, 2.79614739e-04, 3.42191434e-04, 4.18766684e-04,
       5.12469082e-04, 6.27124987e-04, 7.67413430e-04, 9.39055039e-04,
       1.14904229e-03, 1.40591988e-03, 1.72012560e-03, 2.10440443e-03,
       2.57431039e-03, 3.14881358e-03, 3.85103236e-03, 4.70911357e-03,
       5.75728612e-03, 7.03711536e-03, 8.59898661e-03, 1.05038445e-02,
       1.28252101e-02, 1.56514861e-02, 1.90885420e-02, 2.32625358e-02,
       2.83228820e-02, 3.44451957e-02, 4.18339400e-02, 5.07243606e-02,
       6.13831074e-02, 7.41067363e-02, 8.92170603e-02, 1.07052146e-01,
       1.27951705e-01, 1.52235823e-01, 1.80176593e-01, 2.11963334e-01,
       2.47663801e-01, 2.87185901e-01, 3.30246430e-01, 3.76354517e-01,
       4.24816868e-01, 4.74768924e-01, 5.25231076e-01, 5.75183132e-01,
       6.23645483e-01, 6.69753570e-01, 7.12814099e-01, 7.52336199e-01,
       7.88036666e-01, 8.19823407e-01, 8.47764177e-01, 8.72048295e-01,
       8.92947854e-01, 9.10782940e-01, 9.25893264e-01, 9.38616893e-01,
       9.49275639e-01, 9.58166060e-01, 9.65554804e-01, 9.71677118e-01,
       9.76737464e-01, 9.80911458e-01, 9.84348514e-01, 9.87174790e-01,
       9.89496155e-01, 9.91401013e-01, 9.92962885e-01, 9.94242714e-01,
       9.95290886e-01, 9.96148968e-01, 9.96851186e-01, 9.97425690e-01,
       9.97895596e-01, 9.98279874e-01, 9.98594080e-01, 9.98850958e-01,
       9.99060945e-01, 9.99232587e-01, 9.99372875e-01, 9.99487531e-01,
       9.99581233e-01, 9.99657809e-01, 9.99720385e-01, 9.99771521e-01,
       9.99813307e-01, 9.99847452e-01, 9.99875353e-01, 9.99898151e-01,
       9.99916780e-01, 9.99932002e-01, 9.99944439e-01, 9.99954602e-01])
复制代码
plt.grid()
plt.plot(x,y)
复制代码

scipy-expit-plt-1.png

学习推荐


Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

猜你喜欢

转载自juejin.im/post/7018031368533704741