是否有等效于 R 的 sample() 函数的 Python? [英] Is there a Python equivalent to R's sample() function?

查看:63
本文介绍了是否有等效于 R 的 sample() 函数的 Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 Python 是否有一个等效于 R 中的 sample() 函数.

I want to know if Python has an equivalent to the sample() function in R.

sample()函数使用带替换或不带替换从 x 的元素中获取指定大小的样本.

The sample() function takes a sample of the specified size from the elements of x using either with or without replacement.

语法是:

sample(x, size, replace = FALSE, prob = NULL)

(更多信息此处)

推荐答案

我认为 numpy.random.choice(a, size=None, replace=True, p=None) 可能是什么您正在寻找.

I think numpy.random.choice(a, size=None, replace=True, p=None) may well be what you are looking for.

p 参数对应于 sample() 函数中的 prob 参数.

The p argument corresponds to the prob argument in the sample()function.

这篇关于是否有等效于 R 的 sample() 函数的 Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆