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>You're clearly asking for something outside of <code>numpy</code>. </p>

<p>A <a href="https://docs.python.org/2/library/collections.html#defaultdict-objects" rel="nofollow"><code>defauldict</code></a> with the <em><code>default_factory</code></em> as <code>dict</code> gives a sense of the <em>2D dictionary</em> you want:</p>

<pre><code>&gt;&gt;&gt; from collections import defaultdict
&gt;&gt;&gt; a = defaultdict(dict)
&gt;&gt;&gt; a[23][11] = 1
&gt;&gt;&gt; a[23]
{11: 1}
&gt;&gt;&gt; a[23][11]
1
</code></pre>

python numpy