Calculating quantiles of weighted array First the proviso I'm only an aspiring mathematician.  Secondly forgive how I've articulated this question in Python, but it is essentially a computational problem I'm looking to solve.
I wonder if there's an efficient way to calculate quantile breaks for weighted array (i.e. Numpy array, so possibly mathematical vector?).  By weighted array, consider array x = [x₁, x₂, .., xn] which has a corresponding array of weights w = [w₁, w₂, .., wn].  In my current workflow I unpack x into new array xw in which each element xⁱ is repeated wⁱ times, and I then calculate its distribution statistics (e.g quartiles).  But the unpacking is very computationally expensive so I'm exploring possibility of an alternative.
To describe the problem in Python (also see here):
import numpy as np
import random

## random log distribution
x = np.random.lognormal(mean = 7, sigma = 0.7, size = 10000)
x = np.int64(np.ceil(x))

View histogram:
import matplotlib
import matplotlib.pyplot as plt
tmp = plt.hist(x, bins=1000, alpha=0.6, color='c', ec='c', log=True)


Apply weights w to array x:
def weighted_array(arr, weights):
    repeated_array = list(map(lambda f, i: [f] * int(i), arr, weights))
    return np.array([item for sublist in repeated_array for item in sublist])
    
weighted_array([6,4,2], [1,3,5])   # for example
#> array([6, 4, 4, 4, 2, 2, 2, 2, 2])

## For simplicity let's weight x array by itself (i.e. w = x)
xw = weighted_array(x, x)
len(xw)
#> 14092084

stats = np.quantile(xw, [.05, .25, .5, .75, .95])
print(stats)
#> [ 563. 1101. 1771. 2854. 5523.]

The process of generating xw is very expensive for large arrays of large numbers and easily exhaust system memory.  So I wonder if there is a mathematical way to calculate stats from the original x and w arrays without having to apply the weights to generate xw?
Thanks in advance!

import numpy as np
your_data    = [ 1.7 , 2.2 , 3.9 ]
your_weights = [ 2 , 1 , 5 ]
xw = np.repeat( your_data , your_weights )

You should obtain that your xw is
[ 1.7 , 1.7 , 2.2 , 3.9 , 3.9 , 3.9 , 3.9 , 3.9 ]

Unfortunately numpy doesn't have built in weighted functions for everything, but you can put things together in this way.
