select all dimensions of an ndarray but one
<p>I have an <code>ndarray</code> <code>m</code> with dimension (2,3,4). I want to select a particular dimension index and sum everything else like this:</p>

<pre><code>m[:, 2, :].sum()
</code></pre>

<p>but I need a function to handle the element selection because the <code>ndarray</code> can have different dimensions and the sum should be across various slices. The function would take the dimension (here 0, 1 or 2), and the index (0, 1 or 2 as well) of interest and return <code>m[:, 2, :].sum()</code> if the input is (1, 2). If it is (2, 0), I would expect the have the equivalent of <code>m[:, :, 0].sum()</code>.</p>

<p>I do not know how to write such a function though, something that would allow me to put the slice ":" into a variable maybe? I have not been able to find a solution so far. Thanks!</p>