is there a 2D dictionary in python?
<p>I was about to create a matrix like :</p>

<pre><code>    33  12  23  42  11  32  43  22
33  â   1   1   1   0   0   1   1
12  1   â   1   1   0   0   1   1
23  1   1   â   1   1   1   0   0
42  1   1   1   â   1   1   0   0
11  0   0   1   1   â   1   1   1
32  0   0   1   1   1   â   1   1
43  1   1   0   0   1   1   â   1
22  1   1   0   0   1   1   1   â
</code></pre>

<p>I want to query by horizontal or vertical titles, so I created the matrix byï¼</p>

<pre><code>a = np.matrix('99 33    12  23  42  11  32  43 22;33    99  1   1   1   0   0   1   1;12    1   99  1   1   0   0   1   1;23    1   1   99  1   1   1   0   0;42    1   1   1   99  1   1   0   0;11    0   0   1   1   99  1   1   1;32    0   0   1   1   1   99  1   1;43    1   1   0   0   1   1   99  1;22    1   1   0   0   1   1   1   99')
</code></pre>

<p>I want to have the certain data if I query a[23][11] = 1</p>

<p>so is there a way we can create a 2D dictionary, so that a[23][11] = 1?</p>

<p>Thanks</p>

<p>If I understand correctly you just want to label your row/columns. To stay within the numpy array framework, a simple solution would be to create a mapping between the labels and the array order. I am also going to assume that it is OK to convert the labels into strings as they can be anything (though integers would also be fine). </p>

<pre><code>l = {str(x) : ind for ind , x in enumerate((33,12,23,42,11,32,43,22))}
a = sp.linalg.circulant([99,1,1,1,0,0,1,1])
a[l['32'],l['23']]
</code></pre>

python numpy