Axes labels within numpy arrays
<p>Does np.ndarray have the functionality of carrying axes labels?</p>

<p>Let's say that I have a 2-D array with dimensions being time and speed. I want to actually have both axes labels (time and speed values) embedded in an object, so that the object takes care of the axes whenever I do operations with the array (e.g. slice or even plot).</p>

<p>After searching for a while I haven't found anything. I was about to start coding such a class myself and then I thought about asking here, just in case I've missed something.</p>

<p>Thanks</p>

<h2>EDIT</h2>

<p>Given the comments and answers so far, I think I haven't explained my self clear, or just the reasoning behind what I want is not clear due to an oversimplified example [time, speed].</p>

<p>In the field I work it's common to have recordings from multiple sensors, and then segment the data so that you have multiple samples/events. If each sensor captures a 1-dimensional signal across time, one have dimensions [Sensor, Event, Time] (dimension is implicit in the data itself). </p>

<p>When using pure numpy.ndarray, you'll end up with variables: <code>data</code>, a 3-D array with the recorded data; <code>sensor</code>, a 1-D np.recarray with all the information for each sensor (e.g. name, location, ...); <code>event</code>, a 1-D np.recarray with all the information for each sample/event (e.g. type, offset, ...); and Time, a vector with the time values.</p>

<p>What I want is to have all that information in a single object <code>mydata</code> and don't worry about basic manipulations (slicing). So that <code>mydata[0:3, 1:10]</code> will slice the corresponding dimensions accordingly.</p>

<p>I agree that things like plotting will be data specific, but I'll happily code a subclass of such object with some extra functions (e.g. <code>plot</code>).</p>

<h2>Why would this be useful?</h2>

<p><strong>Readability</strong>: Compare</p>

<pre><code>data1 = data[0:3, 1:10]
sensor1 = sensor[0:3]
event1 = event[1:10]
time1 = time
</code></pre>

<p>with a simple</p>

<pre><code>mydata1 = mydata[0:3, 1:10]
</code></pre>

<p><strong>Maintenance</strong>: The second option is obviously easier to maintain and less prone to errors in the correct slicing of all associated variable.</p>

<p><strong>Convenience</strong>: Having all this information in the same place allows to integrate useful and powerful function within the class. For example, if I create a derived class for time series (forcing to have a time axis), I can run time specific functions without having to specify time or sampling frequency (as this information is within the object itself). The idea is to have a base class carrying axes' labels, and specific subclasses will naturally arise when necessary (e.g. one for time series, one for video, one for topographic information, etc) incorporating specialized functionality.</p>

<h2>Close but not exactly</h2>

<p>As @user2357112 mentioned, Pandas' DataFrame is close to what I'm looking for. But, apart from the fact that N-D arrays is still experimental, it seems to be too much oriented to a table-like behaviour (for what I've read so far), e.g. treating the first dimension differently than the others (items vs columns).</p>

<h2>Is it worth it?</h2>

<p>The above may seem trivial, and not worth the effort, but I programmed a subclass of np.ndarray with such functionality a few years ago and I can assure you it made my life and code so much easier! (The specific application was similar to the example above [sensor, sample, time]). But that was back when I was learning python and the way I coded it isn't what you'll call pretty. It also has some fundamental faults, like the axes labels not following the same share-memory rules as np.ndarray.</p>

<p>Before embarking in the trouble of rewrite this thing and make it public, I wanted to know if there's something similar out there.</p>