Skip to content
Advertisement

Convert dictionary with coordinates and values to 2D array

Assume the next dictionary is given:

JavaScript

In the dictionary above each key displays a point in the matrix (x, y) and a value displays the value found in the matrix. How could I construct an array that will contain the values located at each point x, y?

According to the dictionary above the expected result is:

JavaScript

Advertisement

Answer

You could use np.add.at, defining the shape of the array beforehand from the keys:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement