Issue
Hi guys how would I go on converting numpy arrays as such:
[[ 8.82847075 -5.70925653]
[ 1.07032615 -1.77975378]
[-10.41163742 -0.33042086]
[ 0.23799394 5.5978591 ]
[ 7.7386861 -4.16523845]]
To what I desire in Python 3.10. That includes having the keys and values rounded to the nearest integer:
{'9':-6, '1':-2, '-10':0, '0':6, '8':-4}
Solution
The following should work
a = np.round(a)
d = dict(zip(a[:, 0].astype(str), a[:, 1]))
Note: Equal keys will merge.
Answered By - EuxhenH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.