📜  python numba - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:22.129000             🧑  作者: Mango

代码示例1
from numba import jit
import random

@jit(nopython=True)
def monte_carlo_pi(nsamples):
    acc = 0
    for i in range(nsamples):
        x = random.random()
        y = random.random()
        if (x ** 2 + y ** 2) < 1.0:
            acc += 1
    return 4.0 * acc / nsamples