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 :: pickling python example 
Python :: print out session information django 
Python :: flask api with parameter 
Python :: python list files in directory 
Python :: python loop backward 
Python :: slicing tuples 
Python :: swap 2 no in one line python 
Python :: how to find unique values in numpy array 
Python :: how to create barcode in python 
Python :: comment out multiple lines in python 
Python :: how to join tables in python 
Python :: how to make a username system using python 
Python :: BaseSSHTunnelForwarderError: Could not establish session to SSH gateway 
Python :: how to show bar loading in python in cmd 
Python :: try catch python with open 
Python :: how to make a button open a new window in python 
Python :: re date python 
Python :: pairwise function python 
Python :: What will be the output of the following program? 
Python :: how to make a python program on odd and even 
Python :: python mqtt subscribe code 
Python :: python how to get the angle between two points by only their x,y 
Python :: how to check a string is empty in python 
Python :: converting datatypes 
Python :: python how to drop columns from dataframe 
Python :: NLP text summarization with Luhn 
Python :: binary to decimal in python without inbuilt function 
Python :: #pip install commands 
Python :: split the column value and take first value in pandas 
Python :: function to remove punctuation in python 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =