Lazy sorting with dask (bootstrapping problem)

Hi @dougrichardson. I think the easiest and fastest way to get the quantiles is using something like this:

quantiles = (samples < obs).mean("iteration")

If you’re really wanting to use your get_quantile function, the easiest way to wrap a function that works on 1D arrays is to use the vectorize argument on apply_ufunc. E.g. in your case:

quantiles = xr.apply_ufunc(
        get_quantile,
        obs,
        samples,
        input_core_dims=[[], ['iteration']],
        output_core_dims=[[]],
        vectorize=True,
        dask='parallelized'
    )

Note, vectorize is provided primarily for convenience, not performance - it is essentially just a for loop. It would be possible to rewrite your function so that you could use apply_ufunc without vectorize=True, but I’m not sure it’s worth going into that here as I think my first suggestion is probably better.

3 Likes