我是靠谱客的博主 帅气高跟鞋,这篇文章主要介绍[numpy]random.choice()随机选取内容,现在分享给大家,希望可以做个参考。

概述:

复制代码
1
2
可以从一个int数字或1维array里随机选取内容,并将选取结果放入n维array中返回。

说明:

numpy.random.choice(a, size=None, replace=True, p=None)

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
a : 1-D array-like or int If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if a was np.arange(n) size : int or tuple of ints, optional replace : boolean, optional Whether the sample is with or without replacement p : 1-D array-like, optional The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.

示例

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
>>> np.random.choice(5, 3) array([0, 3, 4]) >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) array([3, 3, 0]) >>> np.random.choice(5, 3, replace=False) array([3,1,0]) >>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) array([2, 3, 0]) >>> 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'],

官方介绍

http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.random.choice.html

最后

以上就是帅气高跟鞋最近收集整理的关于[numpy]random.choice()随机选取内容的全部内容,更多相关[numpy]random内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

评论列表共有 0 条评论

立即
投稿
返回
顶部