I want to append multiple values with same key in dictionary.
mydict={'dd6729': np.array([-0.06136101]),
'941a60': np.array([-0.03989978])}
Desired Output:
{'dd6729': [array([-0.06136101]),array([-0.06136101])], '941a60': [array([-0.03989978]),array([-0.06136101])]}
I tried something like this :
for i,v in mydict.items():
mydict[i].append(v)
print(mydict)
but got error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-398-fbc8d90525de> in <module>
1 for i,v in mydict.items():
----> 2 mydict[i].append(v)
3 print(mydict)
4
AttributeError: 'numpy.ndarray' object has no attribute 'append'
As the values are Numpy array so I am unable to append.
question from:https://stackoverflow.com/questions/66062020/append-multiple-value-in-dictionary-values-with-same-key