I want to print ‘array’ inside the dictionary but my code gives me ‘each value’ of the array.
for example, “array_ex” is a dictionary and has values like below with 12 rows for each array…
JavaScript
x
11
11
1
{"0_array": array([[17., 20., 15., , 42., 52., 32.],
2
[24., 33., 19., , 100., 120., 90.],
3
,
4
[2., 3., 4., , 1., 3., 4.],
5
[10., 11., 12., , 13., 16., 17.]]),
6
"1_array": array([[20., 20., 15., , 42., 43., 35.],
7
[52., 33., 22., , 88., 86., 90.],
8
,
9
[10., 11., 17., , 71., 23., 24.],
10
[34., 44., 28., , 42., 43., 17.]])}
11
and I want to get each row of the array as a result.
JavaScript
1
2
1
array([17., 20., 15., , 42., 52., 32.])
2
However, my code returns each value of the array. How can I fix my code?
JavaScript
1
5
1
for i in array_ex:
2
for j in range(13): #cuz each key has 12 arrays
3
for m in array_ex[i][j]:
4
print(m)
5
Advertisement
Answer
Simply loop over the rows:
JavaScript
1
4
1
for i,a in array_ex.items(): # or for a in array_ex.values()
2
for row in a:
3
print(row)
4