Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python print array inside the dictionary

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading