Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python numba

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
Comment

numba for python

from numba import njit
import random

@njit
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
Comment

PREVIOUS NEXT
Code Example
Python :: how to chose version of python 
Python :: dictionary python 
Python :: python manage.py collectstatic 
Python :: remove grid in imshow 
Python :: add text in figure coordinatesp ython 
Python :: how to record youtube cc in python 
Python :: how to make a bot send whatever you dm it into a server discord.py 
Python :: Access python http.server on google colab 
Python :: how to do tail recursion in python 
Python :: reverse order of dataframe rows 
Python :: python __add__ 
Python :: dict to list python 
Python :: add space before and after string python 
Python :: python selenium element not interactable while headless 
Python :: how to redirect where requests library downloads file python 
Python :: even in python 
Python :: matplotlib force scientific notation and define exponent 
Python :: PySimpleGUI multifiles select 
Python :: python listas por comprension 
Python :: displaying data from this column where value is this python 
Python :: last element of python list 
Python :: python combinations function 
Python :: printed in a comma-separated sequence on a single line. 
Python :: numpy concatenate arrays 
Python :: python grab results from cursor.execute 
Python :: dates and times in python 
Python :: how to install pywhatkit in pycharm 
Python :: compiling python code 
Python :: container with most water python code leetcode 
Python :: using python for rest api 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =