I'm trying to find a nice way to take a 2d numpy array and attach column and row names as a structured array. For example:
import numpy as np
column_names = ['a', 'b', 'c']
row_names = ['1', '2', '3']
matrix = np.reshape((1, 2, 3, 4, 5, 6, 7, 8, 9), (3, 3))
# TODO: insert magic here
matrix['3']['a'] # 7
I've been able to use set the columns like this:
matrix.dtype = [(n, matrix.dtype) for n in column_names]
This lets me do matrix[2]['a']
but now I want to rename the rows so I can do matrix['3']['a']
.