You can write a thinly wrapped subclass to np.ndarray . But keeping the correspondence between dimensions and names can be tricky.
class NamedArray(np.ndarray): def __new__(cls, *args, **kwargs): obj = np.ndarray(args[0], **kwargs).view(cls) return obj def __init__(self, *args, **kwargs): self.dim_names = None if len(args) == 2: self.dim_names = args[1] def sum(self, *args, **kwargs): if (self.dim_names is not None) and (type(kwargs['axis']) == str): axis_name = kwargs.pop('axis') axis_ind = self.dim_names.index(axis_name) kwargs['axis'] = axis_ind return super().sum(*args, **kwargs)
Edit: Pandas DataFrame is currently pretty close to what the OP asked.
source share