2D numpy 配列を取得し、列と行の名前を構造化配列として添付する良い方法を見つけようとしています。例えば:
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
次のように列を設定して使用できました。
matrix.dtype = [(n, matrix.dtype) for n in column_names]
これでできますmatrix[2]['a']
が、行の名前を変更したいので、できるようになりましたmatrix['3']['a']
。