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…
{"0_array": array([[17., 20., 15., ..., 42., 52., 32.], [24., 33., 19., ..., 100., 120., 90.], ..., [2., 3., 4., ..., 1., 3., 4.], [10., 11., 12., ..., 13., 16., 17.]]), "1_array": array([[20., 20., 15., ..., 42., 43., 35.], [52., 33., 22., ..., 88., 86., 90.], ..., [10., 11., 17., ..., 71., 23., 24.], [34., 44., 28., ..., 42., 43., 17.]])}
and I want to get each row of the array as a result.
array([17., 20., 15., ..., 42., 52., 32.])
However, my code returns each value of the array. How can I fix my code?
for i in array_ex: for j in range(13): #cuz each key has 12 arrays for m in array_ex[i][j]: print(m)
Advertisement
Answer
Simply loop over the rows:
for i,a in array_ex.items(): # or for a in array_ex.values() for row in a: print(row)