Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy random for string

>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
>>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],
      dtype='|S11')



fruits = ['apple', 'banana', 'orange', 'grape']
subset_size = int(0.7 * len(fruits))
np.random.choice(fruits, subset_size, replace=False)
# array(['grape', 'banana'], dtype='<U6')
Comment

PREVIOUS NEXT
Code Example
Python :: Python NumPy repeat Function Example 
Python :: how to enter a int in python 
Python :: circle circumference python 
Python :: next() python 
Python :: Python program to combine each line from first file with the corresponding line in second file 
Python :: Find column whose name contains a specific string 
Python :: Python of add two numbers 
Python :: get dict values in list python 
Python :: how to exit program in python 
Python :: Adding labels to histogram bars in matplotlib 
Python :: remove leading and lagging spaces dataframe python 
Python :: python get the intersection of two lists 
Python :: delete column in dataframe pandas 
Python :: traversing a tree in python 
Python :: how to make a loading gif in pyqt5 
Python :: how to get a int from string python 
Python :: python namespace 
Python :: progress bar python text 
Python :: how to run fastapi with code python 
Python :: python makedir 
Python :: python async await run thread 
Python :: selenium click on item in a list 
Python :: python split by first match 
Python :: how can i remove random symbols in a dataframe in Pandas 
Python :: python timeout exception 
Python :: all() python 
Python :: python dict remove duplicates where name are not the same 
Python :: pandas dataframe get first n rows 
Python :: how to convert tuple into list in python 
Python :: tkinter copy paste 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =