Answers for "r functions equivalent in python"

0

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
Posted by: Guest on December-01-2020
0

what is r in python

# a normal string which treats a back slash as a special character and changes some properties of it
("D:UserslegendaryPicturesSaved Picturesbugatti.jpg")

#we use r string to write paths without any conflit since they contain backshlases

# >>> this is an r string
(r"D:UserslegendaryPicturesSaved Picturesbugatti.jpg")
Posted by: Guest on April-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language