Numpy Tutorial => Selecting A Random Sample From An Array

Download numpy (PDF)

numpy

  • Getting started with numpy
  • Arrays
  • Boolean Indexing
  • File IO with numpy
  • Filtering data
  • Generating random data
    • Creating a simple random array
    • Creating random integers
    • Generating random numbers drawn from specific distributions
    • Selecting a random sample from an array
    • Setting the seed
  • Linear algebra with np.linalg
  • numpy.cross
  • numpy.dot
  • Saving and loading of Arrays
  • Simple Linear Regression
  • subclassing ndarray

numpy

  • Getting started with numpy
  • Arrays
  • Boolean Indexing
  • File IO with numpy
  • Filtering data
  • Generating random data
    • Creating a simple random array
    • Creating random integers
    • Generating random numbers drawn from specific distributions
    • Selecting a random sample from an array
    • Setting the seed
  • Linear algebra with np.linalg
  • numpy.cross
  • numpy.dot
  • Saving and loading of Arrays
  • Simple Linear Regression
  • subclassing ndarray
numpy Generating random data Selecting a random sample from an array

Fastest Entity Framework Extensions

Bulk Insert Bulk Delete Bulk Update Bulk Merge

Example

letters = list('abcde')

Select three letters randomly (with replacement - same item can be chosen multiple times):

np.random.choice(letters, 3) ''' Out: array(['e', 'e', 'd'], dtype='<U1') '''

Sampling without replacement:

np.random.choice(letters, 3, replace=False) ''' Out: array(['a', 'c', 'd'], dtype='<U1') '''

Assign probability to each letter:

# Choses 'a' with 40% chance, 'b' with 30% and the remaining ones with 10% each np.random.choice(letters, size=10, p=[0.4, 0.3, 0.1, 0.1, 0.1]) ''' Out: array(['a', 'b', 'e', 'b', 'a', 'b', 'b', 'c', 'a', 'b'], dtype='<U1') '''

Got any numpy Question?

Ask any numpy Questions and Get Instant Answers from ChatGPT AI: ChatGPT answer me! pdf PDF - Download numpy for free Previous Next This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow logo rip SUPPORT & PARTNERS
  • Advertise with us
  • Contact us
  • Cookie Policy
  • Privacy Policy
STAY CONNECTED

Get monthly updates about new articles, cheatsheets, and tricks.

Subscribe Cookie This website stores cookies on your computer. We use cookies to enhance your experience on our website and deliver personalized content. For more details on our cookie usage, please review our Cookie Policy and Privacy Policy Accept all Cookies Leave this website

Từ khóa » Np Choice