Is there an easy way to access array elements by (string) key as well as by index? Suppose I have an array like this:
x = array([[0, 4, 9, 1],
[1, 3, 9, 1],
[3, 5, 6, 2],
[6, 2, 7, 5]])
I am looking for way to specify a set of keys (for example ('A', 'C', 'G', 'T')) that can be used as an alias for an index.
So x['A', 'C'], x[0,'C'], x['A', 1], and x[0,1] all return the value 4;
x['G', :] is the same as x[2, :], and so on.
I know that this can be achieved by subclassing a numpy array and overriding __getitem__ and __setitem__, but subclassing gets complicated very quickly, so I was wondering if there is a simpler or better way to do this.
dd = {'A':0, 'C':1, ...}and index with x[dd['A'],:]. I'd look at thenumpy.lib.index_tricks.py` file to see classes that define their own indexing.