Convert array dictionary to a dictionary python

try this:

output = {}
for key in originalDict:
    output[key] = originalDict[key].tolist()

Where originalDict is the dictionary you showed us, with numpy arrays.

There’s probably a neater way of writing it but it should work.

EDIT: with regards to your comment, if you just need the inner list, then index the first element of each value in the dict after converting it, like this:

    output = {}
    for key in originalDict:
        output[key] = originalDict[key].tolist()[0]

Leave a Comment