theta.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:planetplanet 作者: rodluger 项目源码 文件源码
def sample():
    '''
    Draw a sample from the distribution of polar angle of the angular 
    momentum vector, :math:`\\theta`, computed using the Monte Carlo 
    technique discussed in the paper. 

    .. plot::
         :align: center

         from planetplanet.photo import theta
         import matplotlib.pyplot as pl
         x = [theta.sample() for i in range(10000)]
         pl.hist(x, bins = 50)
         pl.xlabel(r'$\\theta$ [deg]', fontweight = 'bold')
         pl.ylabel('Probability', fontweight = 'bold')
         pl.show()

    '''

    y = np.random.random()
    f = lambda x: CDF(x) - y
    while np.sign(f(0)) == np.sign(f(1)):
        y = np.random.random()
        f = lambda x: CDF(x) - y
    return brentq(f, 0, 1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号