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

numpy generate random array

from numpy import random
randArray = random.random(size=(2,4))
 
#输出
#array([[0.93848018,0.42005976,0.81470729,0.98797783],[0.12242703,0.42756378,0.59705163,0.36619101]])
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 :: python boxplot legend 
Python :: add button to streamlit 
Python :: python format float 
Python :: unpack dictionaryp 
Python :: remover espaços string python 
Python :: reverse linked list with python 
Python :: count plot 
Python :: calcolatrice online 
Python :: python how to return max num index 
Python :: insert video in tkinter 
Python :: python pil bytes to image 
Python :: python comprehension with sum 
Python :: convert 2d list to 1d python 
Python :: colored text python 
Python :: print progress without next line python 
Python :: pyspark min column 
Python :: python -m pip install 
Python :: python class tostring 
Python :: python how to set multiple conditional for single var 
Python :: flask api response code 
Python :: floyd triangle python 
Python :: how to add special token to bert tokenizer 
Python :: decode base64 with python 
Python :: how to replace single string in all dictionary keys in python 
Python :: kill turtle 
Python :: python get filename without extension 
Python :: python read excel sheet name 
Python :: convert birth date to age pandas 
Python :: how to get height in pyqt5 
Python :: main arguments python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =