Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

R sample() funciton in python


import numpy as np
np.random.choice(values, size=1000,  replace=True, p=probability)

# values is the input values that correspond to the weights
# size is the number of samples to generate
# Replace specifies if it's with or without replacement
# p is the probability of choosing each corresponding value in values
Comment

python equivalent of R sample function

lstDemand = [0, 1000, 2000, 3000, 4000, 5000, 6000]
lstProbability = [.02, .03, .05, .08, .33, .29, .20]

# Python Equivalent of R sample() function
numpy.random.choice(lstDemand, size=1000, replace=True, p=lstProbability)

# lstDemand = the values or options
# size = how many values the output list should have (None = 1)
# replace = sampling with or without replacement
# p = the probability of choosing each corresponding value in lstDemand
Comment

PREVIOUS NEXT
Code Example
Python :: python remove first item in list 
Python :: do while python 
Python :: assert with message python 
Python :: django model choice field from another model 
Python :: Python Tkinter MenuButton Widget 
Python :: s.cookie.set python 
Python :: python list function 
Python :: Broadcasting with NumPy Arrays Two dimension array dimension array Example 
Python :: functools.cached_property objects in python 
Python :: #index operator in python 
Python :: django add queury parameters to reverse 
Python :: deleting a tuple in python 
Python :: foreach loop in python 
Python :: how to print a message in python 
Python :: filter in python 
Python :: Syntax of Opening a File in python 
Python :: random.randint(0,20) + pyrthon 
Python :: convert image to binary python 
Python :: how to reverse list python 
Python :: normalize a group in countplot 
Python :: pivot index 
Python :: closures in python 
Python :: post from postman and receive in python 
Python :: numpy array [-1] 
Python :: python loop array 
Python :: deleting key from dictionary 
Python :: {"message": "401: Unauthorized", "code": 0} discord 
Python :: df loc 
Python :: double underscore methods python 
Python :: are logN and (lognN) same 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =