How do I replace values in 2D numpy array using a dictionary of {value:(row#,column#)} pairs
<pre><code> import numpy as np
</code></pre>

<p>the array looks like so:</p>

<pre><code> array = np.zeros((10,10))
 array = 
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]
</code></pre>

<p>the dictionary is like this:</p>

<pre><code> dict = {72: (3, 4), 11: (1, 5), 10: (2, 4), 43: (2, 3), 22: (24,35), 11: (8, 9)}
</code></pre>

<p>I want to iterate over the array and replace any grid points that match the grid coordinates in the dictionary with the corresponding value in the dictionary</p>

<p>i am after an output like this:</p>

<pre><code> [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0. 11.  0.  0.  0.  0.]
 [ 0.  0.  0. 43. 10.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0. 72.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0. 11.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]
</code></pre>

<p>** i have edited the question the provide co-ordinates that sit within the array except for 1 exception. I also provided an example of the desired output</p>

<p>I hope I understood your question correctly</p>

<pre><code>array = np.zeros((10,10))
data = {72: (3, 4), 11: (1, 5), 10: (2, 4), 43: (2, 3), 22: (24,35)}

for i in data.keys():
    try:
        array[data[i][0],data[i][1]] = float(i)
    except IndexError:
       pass
print array
</code></pre>

<p>I changed the indices such that it fits into your 10 x 10 array (I assume you work with a bigger array in your real example) </p>

<p>I iterate over all keys in the dictionary (the values). The program then tries to set this value in the array at the given coordinates.
I pass IndexErrors for the case some coordinates are outside the array (like the last in this example.</p>

<p><strong>EDIT</strong></p>

<p>This solution only works if your keys are unique. If they are not I would recommend the solution of @Osssan.</p>

python numpy dictionary