np.random.choice 参数replace

简介: np.random.choice 参数replace
  1. replace为True,即可以重复取值


  1. False,则只能取一次
(p2) PS C:\Users\livingbody> python
Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.random.choice(1000,10, replace=True)
array([417, 406, 891, 325, 581, 939, 178, 855, 692, 677])
>>> np.random.choice(1000,10, replace=False)
array([ 49,  21, 375, 874,  39, 354, 417,  23, 963, 825])
>>> np.random.choice(10,10, replace=False)
array([9, 1, 7, 2, 5, 0, 3, 4, 6, 8])
>>> np.random.choice(10,10, replace=False)
array([9, 0, 3, 4, 1, 8, 2, 6, 7, 5])
>>> np.random.choice(10,10, replace=True)
array([4, 6, 3, 0, 4, 7, 4, 4, 7, 1])
>>> np.random.choice(10,10, replace=True)
array([7, 4, 0, 4, 1, 9, 2, 6, 4, 4])
>>>


目录
相关文章
|
3月前
random.choice(seq)
random.choice(seq)
16 1
|
3月前
numpy.random.rand(d0, d1, …, dn)
numpy.random.rand(d0, d1, …, dn)
17 0
|
9月前
|
Python
Python random 随机函数(random、uniform、randint、choice、choices、randrange、shuffle、sample)
Python random 随机函数(random、uniform、randint、choice、choices、randrange、shuffle、sample)
78 0
|
11月前
|
Python
【Numpy】深入剖析Numpy.arange()与range()的区别
【Numpy】深入剖析Numpy.arange()与range()的区别
103 0
|
数据安全/隐私保护
Random的nextInt()用法
Random的nextInt()用法
159 0
|
Python
TypeError: img is not a numpy array, neither a scalar
TypeError: img is not a numpy array, neither a scalar
201 0
|
Linux Python
ValueError: empty range for randrange() (0, 0, 0)
ValueError: empty range for randrange() (0, 0, 0)
|
Python
【numpy】random.RandomState()函数用法详解
【numpy】random.RandomState()函数用法详解
【numpy】random.RandomState()函数用法详解
|
Java
Random rand = new Random(47);的简单解释
Random rand = new Random(47);的简单解释
271 0