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>Another possibility is to use tuples as the dictionary keys</p>

<pre><code>dict((33,12):1, (23,12):1, ...]
</code></pre>

<p><code>scipy.sparse</code> has a sparse matrix format that stores it's values in such a dictionary.  With your values such a matrix would represent a 50x50 matrix with mostly 0 values, and just 1's at these selected coordinates.</p>

<p>Keep in mind that the keys of a dictionary (ordinary at least) are not ordered</p>

<p>What are going to be doing with this data?  A dictionary, whether type or nested, is good for one kind of usage, but bad for others.  A matrix such as you sample is better for other things, like operations along rows or columns.  The dictionary format largely obscures that kind of ordered layout.</p>

python numpy