�一些索引方面的技巧：</p>
<pre><code>def demean_axis(arr, axis=0):
    means = arr.mean(axis)

    # This generalizes things like [:, :, np.newaxis] to N dimensions
    indexer = [slice(None)] * arr.ndim
    indexer[axis] = np.newaxis
    return arr - means[indexer]</code></pre>
</div>
<div id="section-15.3.2" class="section level3">
<h3><span class="header-section-number">A.3.2</span> 通过广播设置数组的值</h3>
<p>算术运算所遵循的广播原则同样也适用于通过索引机制�