[英]Is there any random.choices() function in Python Processing
有誰知道是否有任何等價於
import random
random.choices(population, weitghts, k=1)
.. 用於處理 Python 模式?。
我想為這個StackOverflow 問題部署一個算法,但找不到所需的函數。
Processing 的 Python 模式是建立在 Jython 之上的,Jython 仍然沒有爬出 Python 2 時代(它只是從 2.5 到 Python 2.7 兼容,在 2015 年,2.7 發布后的五年)。
random.choices
是在 Python 3.6 中引入的; 即使用於處理的 Python 模式提供對所有 Python 功能的完全訪問(我很難確定是否可以),Jython 的 2.7 兼容性意味着它幾乎沒有在 Python 3.1 之后引入的功能,因此random.choices
不重新實現random.choices
將不可用從頭開始。 當然, random.choices
的代碼是開源的並發布在網上,因此您始終可以自己將其向后移植到 Python 2(以及它所依賴的itertools.accumulate
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.