I need a little help with a small task.
I have a dictionary with a tuple of integers (e.g. (1,1), (0,2), etc.)
I want to be able to put this in a matrix that looks like this...
(0,0) | (0,1) | (0,n)
______|________|_______
(1,0) | (1,1) | (1,n)
______|________|_______
(m,0) | (m,1) | (m,n)
Here is a code that I thought would help me append each value on the matrix with the keys in my dictionary.
import numpy as np
rows = 3
columns = 4
my_dict = {}
for i in range(rows):
for j in range(columns):
my_dict[i,j] = []
A = np.arange(rows*columns).reshape([rows,columns])
for keys in my_dict.keys():
for i in range(rows):
for j in range(columns):
A[i,j] = my_dict[keys]
I get the following error.
ValueError: setting an array element with a sequence.
I believe I am getting this error because it is assigning the key's value, respectfully, which is an empty list. This isn't my intention. I want to associate each element in the matrix with keys associated with my dictionary.
Edit: The desired output should be the following...
(0,0) | (0,1) | (0,2) | (0,3) |
______|________|_______|________|
(1,0) | (1,1) | (1,2) | (1,3) | = A
______|________|_______|________|
(2,0) | (2,1) | (2,2) | (2,3) |
______|________|_______|________|