简体   繁体   English

Python 处理中是否有任何 random.choices() 函数

[英]Is there any random.choices() function in Python Processing

Does anybody know if there is any equivalent to有谁知道是否有任何等价于

import random
random.choices(population, weitghts, k=1)

.. for Python Mode for Processing ?. .. 用于处理 Python 模式?。

I want to deploy an algorithm for this StackOverflow question, but can't find the desired function.我想为这个StackOverflow 问题部署一个算法,但找不到所需的函数。

Python mode for Processing is built on Jython, and Jython still hasn't crawled out of the Python 2 era (it only moved to Python 2.7 compatibility, from 2.5, in 2015, half a decade after 2.7 released). Processing 的 Python 模式是建立在 Jython 之上的,Jython 仍然没有爬出 Python 2 时代(它只是从 2.5 到 Python 2.7 兼容,在 2015 年,2.7 发布后的五年)。

random.choices was introduced in Python 3.6 ;random.choices是在 Python 3.6 中引入的 even if Python mode for Processing offered full access to all Python features (and I have a hard time determining if it does), Jython's 2.7 compatibility means it has almost no features introduced after Python 3.1, so random.choices is not available without reimplementing it from scratch.即使用于处理的 Python 模式提供对所有 Python 功能的完全访问(我很难确定是否可以),Jython 的 2.7 兼容性意味着它几乎没有在 Python 3.1 之后引入的功能,因此random.choices不重新实现random.choices将不可用从头开始。 Of course, the code for random.choices is open source and posted online , so you could always just backport it to Python 2 yourself (along with itertools.accumulate , which it relies on).当然, random.choices的代码是开源的并发布在网上,因此您始终可以自己将其向后移植到 Python 2(以及它所依赖的itertools.accumulate )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM