Quick way to access first element in Numpy array with arbitrary number of dimensions?
<p>I have a function that I want to have quickly access the first (aka zeroth) element of a given Numpy array, which itself might have any number of dimensions.  What's the quickest way to do that?</p>

<p>I'm currently using the following:</p>

<pre><code>a.reshape(-1)[0]
</code></pre>

<p>This reshapes the perhaps-multi-dimensionsal array into a 1D array and grabs the zeroth element, which is short, sweet and often fast.  However, I think this would work poorly with some arrays, e.g., an array that is a transposed view of a large array, as I worry this would end up needing to create a copy rather than just another view of the  original array, in order to get everything in the right order.  (Is that right?  Or am I worrying needlessly?)  Regardless, it feels like this is doing more work than what I really need, so I imagine some of you may know a generally faster way of doing this?</p>

<p>Other options I've considered are creating an iterator over the whole array and drawing just one element from it, or creating a vector of zeroes containing one zero for each dimension and using that to fancy-index into the array.  But neither of these seems all that great either.</p>