numpy.random.choice中的替换意味着什么?

[英]What does replacement mean in numpy.random.choice?


Here explains the function numpy.random.choice. However, I am confused about the third parameter replace. What is it? And in which case will it be useful? Thanks!

这里解释了函数numpy.random.choice。但是,我对第三个参数替换感到困惑。它是什么?在哪种情况下它会有用吗?谢谢!

2 个解决方案

#1


29  

It controls whether the sample is returned to the sample pool. If you want only unique samples then this should be false.

它控制是否将样本返回到样本池。如果您只想要唯一的样本,那么这应该是假的。

#2


15  

You can use it when you want sample some elements from a list, and meanwhile you want the elements no repeat, then you can set the "replace=False".
eg.

当您想要从列表中采样某些元素时,可以使用它,同时您希望元素不重复,然后您可以设置“replace = False”。例如。

from numpy import random as rd

ary = list(range(10))
# usage
In[18]: rd.choice(ary, size=8, replace=False)
Out[18]: array([0, 5, 9, 8, 2, 1, 6, 3])  # no repeated elements
In[19]: rd.choice(ary, size=8, replace=True)
Out[19]: array([4, 9, 8, 5, 4, 1, 1, 9])  # elements may be repeated
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2016/11/19/c0583ec502783b6e3bd8503538b441c6.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告