Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

np random array

# uniform distribution over [0, 1)
np.random.rand(3, 3)
# [[0.20966286 0.72581506 0.78926387]
#  [0.85719525 0.00163033 0.45001818]
#  [0.17630303 0.40184026 0.89585902]]

# discrete uniform distribution in [0, 10)
np.random.randint(0, 10, size=[3,3])
# [[6 8 4]
#  [1 3 3]
#  [6 9 7]]

# normal distribution around 5 with standard deviation of 2
np.random.normal(5, 2, size=[3,3])
# [[3.8768528  5.73747086 3.63564872]
#  [5.49814587 2.62757122 3.61948982]
#  [3.36409537 7.86431236 5.16509868]]
Comment

np.random

np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random
Comment

np.random.randn()

>>> 2.5 * np.random.randn(2, 4) + 3
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],  #random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]]) #random
Comment

np.random.rand()

# train test split
df = pd.read_csv('file_location')
mask = np.random.rand(len(df)) < 0.8
train  = df[mask]
test = df[~mask]
Comment

PREVIOUS NEXT
Code Example
Python :: what are while loops 
Python :: Facet Grid for Bar Plot with non-shared y axes (CatPlot) 
Python :: python click activator 
Python :: django serializer method field read write 
Python :: python child class init 
Python :: speechapi 
Python :: replace NaN value in pandas data frame 
Python :: opencv find image contained within an image 
Python :: python pprint on file 
Python :: how do you make plot show with matplotlib ion method 
Python :: Print only small Latin letters a found in the given string. 
Python :: python sleeping with a varible 
Python :: how to join two string series python 
Python :: kill os system by pid python script 
Python :: python glob sort numerically 
Python :: how write a date with th and nd in python 
Python :: was en francais 
Python :: Site Download Python3 
Python :: how to convert multiple jupyter notebook into python script with single commanf 
Python :: docs in python parameter 
Python :: make n copies of item in list 
Python :: get top feature gridsearchcv 
Python :: host python discord bot free 
Python :: solving differential equations in python 
Python :: int and text on same line python 
Python :: python ocr pdf dataframe 
Python :: how to change the type of a values in list from str to object python 
Python :: paramhans ramchandra das 
Python :: use of numpy matrix in tkinter python 3 
Python :: Separating a relational plot based on a sixth variable | seaborn relational plot 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =