I have a NumPy2d array that is a symmetric matrix (square matrix where the numbers above the diagonal are the same as the number below the diagonal)
Example input matrix:
edgeMatrix = np.array([[0., 2., 9.],
[2., 0., 1.],
[9., 1., 0.]])
I am looking for a very efficient way to convert this large matrix into a nested dictionary where the first key is the row index of the matrix and the second dict key is the column index of the matrix. ex:
Desired resulting nested dict format:
edgeDict[0][0] = 0
edgeDict[0][1] = 2
edgeDict[0][2] = 9
edgeDict[1][0] = 2
edgeDict[1][1] = 0
edgeDict[1][2] = 1
edgeDict[2][0] = 9
edgeDict[2][1] = 1
edgeDict[2][2] = 0
I have tried using dict(enumerate(edgeMatrix.flatten(), 1)), but failed to figure out how to get the nested aspect of this working.
dictofdict? A list of lists would have the same usage syntax (for reading data/setting existing elements) but would be faster to allocate, smaller in memory footprint and faster in lookup performance. - Matteo Italia