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 :: python jokes 
Python :: Python Tkinter timer animation 
Python :: how to underline text in tkinter 
Python :: apostrophe in python 
Python :: python ddos 
Python :: python string replace index 
Python :: how to enable execution time in jupyter lab 
Python :: python 3.9 features 
Python :: pandas dataframe column names 
Python :: how to pair up two lists in python 
Python :: ipython.display install 
Python :: print output python to file 
Python :: subprocess print logs 
Python :: wolfram alpha python module 
Python :: convert dict to dataframe 
Python :: case in python 
Python :: python how to get the screen size 
Python :: python remove last element from list 
Python :: tkinter frame example 
Python :: how to write to the end of a file in python 
Python :: reverse geocoding python 
Python :: python cut string after character 
Python :: python string to list with separator 
Python :: death stranding 
Python :: how to write to a netcdf file using xarray 
Python :: packing and unpacking in python 
Python :: plotly heatmap with label 
Python :: python convert number in array to integer 
Python :: how to play audio in python 
Python :: remove index from dataframe pandas 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =