python in learning math
2016-05-10 19:42
375 查看
limit behavior of transition probability of a given markov chain
P.S. Note that below code use @ operator which requires python 3.5 or above, see matrix_operator.
plot a sequence of function with different hyperparameter
Given f(x)=xa−1e−x/b (which is integrand of gamma function when b=1, see Gamma Function, we can plot a series of plots of functions.
the output is show as
P.S. Note that below code use @ operator which requires python 3.5 or above, see matrix_operator.
>>> import numpy as np >>> np.set_printoptions(precision=4) >>> g = lambda trans_mat, cnt=20: reduce(lambda x1, x2: print(x1) or x1@x2, (trans_mat for _ in range(cnt)), np.eye(len(trans_mat))) >>> t, t1 = np.array([[.5,.4,.1],[.3,.4,.3],[.2,.3,.5]]), \ np.array([[.7,0,.3,0],[.5,0,.5,0],[0,.4,0,.6],[0,.2,0,.8]]) >>> g(t,10) [[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]] [[ 0.5 0.4 0.1] [ 0.3 0.4 0.3] [ 0.2 0.3 0.5]] [[ 0.39 0.39 0.22] [ 0.33 0.37 0.3 ] [ 0.29 0.35 0.36]] [[ 0.356 0.378 0.266] [ 0.336 0.37 0.294] [ 0.322 0.364 0.314]] [[ 0.3446 0.3734 0.282 ] [ 0.3378 0.3706 0.2916] [ 0.333 0.3686 0.2984]] [[ 0.3407 0.3718 0.2875] [ 0.3384 0.3708 0.2908] [ 0.3368 0.3702 0.2931]] [[ 0.3394 0.3713 0.2894] [ 0.3386 0.3709 0.2905] [ 0.338 0.3707 0.2913]] [[ 0.3389 0.3711 0.29 ] [ 0.3387 0.371 0.2904] [ 0.3385 0.3709 0.2906]] [[ 0.3388 0.371 0.2902] [ 0.3387 0.371 0.2903] [ 0.3386 0.3709 0.2904]] [[ 0.3387 0.371 0.2903] [ 0.3387 0.371 0.2903] [ 0.3387 0.371 0.2904]] Out[20]: array([[ 0.3387, 0.371 , 0.2903], [ 0.3387, 0.371 , 0.2903], [ 0.3387, 0.371 , 0.2903]])
plot a sequence of function with different hyperparameter
Given f(x)=xa−1e−x/b (which is integrand of gamma function when b=1, see Gamma Function, we can plot a series of plots of functions.
import numpy as np from sympy import * %matplotlib inline x = Symbol('x') def g(a=2.,b=1.): return x**(a-1) * exp(-x/b) for v in np.linspace(0.5,2,6): plot(g(v),(x,0,v-1+4),title = 'a=%s, b=1.0' % v)
the output is show as
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法