引导程序:有没有更快的方法?

时间:2019-02-01 11:05:03

标签: python python-3.x numpy statistics

我正在尝试计算数组总数的引导统计信息,我想知道是否可以提高速度?

from numpy import sum
from numpy.random import choice

def bootstrap(observed_array: array, number_of_bootstraps: int = 10000) -> array:
    number_of_elements = len(observed_array)
    bootstrap_estimates = []
    for _ in range(number_of_bootstraps):
        indices = choice(number_of_elements, size=number_of_elements, replace=True)
        bootstrap_sample = observed_array[indices]
        bootstrap_estimate = bootstrap_sample.sum()
        bootstrap_estimates.append(bootstrap_estimate)
    return array(bootstrap_estimates)

感谢您的任何建议。

0 个答案:

没有答案