<p dir="auto">The problem seems to be the inclusion of a mix of <code class="notranslate">*.c</code>, <code class="notranslate">*.h</code> and <code class="notranslate">*.c.src</code> files in <code class="notranslate">multiarray_src</code>, the list that only include <code class="notranslate">*.*.src</code> files seem to do better.</p>
<p dir="auto">Sometimes, I have a sample of data which I want to divide into bins and then sum an associated vector over all samples within each bin.  This could be accomplished by creating a histogram with array-valued weights.  Perhaps there are other ways to do it, but this seems to be the best conceptual match to what I want to do, and is a very natural extension of <code class="notranslate">np.histogram</code>.</p>
<p dir="auto">In the particular example that I am dealing with at the moment, I want to re-weight my samples according to a 4th-order polynomial of an associated quantity.  That is, I have an array <code class="notranslate">hist_variable</code> with shape <code class="notranslate">(n,)</code>, and another array <code class="notranslate">reweighting_variable</code> also of shape <code class="notranslate">(n,)</code>.  My weights are some polynomial function of <code class="notranslate">reweighting_variable</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rv = reweighting_variable
weights = a0 + a1*rv + a2*rv**2 + a3*rv**3 + a4*rv**4
counts, edges = np.histogram(hist_variable, weights=weights)"><pre class="notranslate"><code class="notranslate">rv = reweighting_variable
weights = a0 + a1*rv + a2*rv**2 + a3*rv**3 + a4*rv**4
counts, edges = np.histogram(hist_variable, weights=weights)
</code></pre></div>
<p dir="auto">This works fine, as long as <code class="notranslate">a0</code>, <code class="notranslate">a1</code>, etc. are known and fixed.  If I instead want to vary <code class="notranslate">a0</code>, <code class="notranslate">a1</code>, etc., then I can create five different histograms:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="counts0, edges = np.histogram(hist_variable)
counts1 = np.histogram(hist_variable, weights=rv, bins=edges)[0]
counts2 = np.histogram(hist_variable, weights=rv**2, bins=edges)[0]
counts3 = np.histogram(hist_variable, weights=rv**3, bins=edges)[0]
counts4 = np.histogram(hist_variable, weights=rv**4, bins=edges)[0]

def weighted_counts(a0, a1, a2, a3, a4):
    return a0*counts0 + a1*counts1 + a2*counts2 + a3*counts3 + a4*counts4"><pre class="notranslate"><code class="notranslate">counts0, edges = np.histogram(hist_variable)
counts1 = np.histogram(hist_variable, weights=rv, bins=edges)[0]
counts2 = np.histogram(hist_variable, weights=rv**2, bins=edges)[0]
counts3 = np.histogram(hist_variable, weights=rv**3, bins=edges)[0]
counts4 = np.histogram(hist_variable, weights=rv**4, bins=edges)[0]

def weighted_counts(a0, a1, a2, a3, a4):
    return a0*counts0 + a1*counts1 + a2*counts2 + a3*counts3 + a4*counts4
</code></pre></div>
<p dir="auto">And then I can choose any <code class="notranslate">a0</code>, <code class="notranslate">a1</code>, etc. that I like, and get my weighted histogram with the function <code class="notranslate">weighted_counts</code>, without performing the expensive <code class="notranslate">np.histogram</code> step again.  This works, but it is not ideal.</p>
<p dir="auto">The reason that it is not ideal is that I must re-do the binning step of <code class="notranslate">np.histogram</code> many times.  This is expensive.  I've tried to create a solution using <code class="notranslate">np.digitize</code> and fancy indexing, but that is also quite slow.  What I wish I could do is</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="weights = array([rv**0, rv**1, rv**2, rv**3, rv**4])
counts_array, edges = np.histogram(hist_variable, weights=weights)"><pre class="notranslate"><code class="notranslate">weights = array([rv**0, rv**1, rv**2, rv**3, rv**4])
counts_array, edges = np.histogram(hist_variable, weights=weights)
</code></pre></div>
<p dir="auto">Can this be implemented efficiently?  It seems like summing array-valued weights shouldn't be drastically slower than summing scalar-valued weights.</p>