gpt4 book ai didi

python - 在 Python 中从数组创建字典

转载 作者:太空狗 更新时间:2023-10-30 02:08:28 25 4
gpt4 key购买 nike

我有 3 个 numpy 数组:

a = numpy.array([['x','y']])
b = numpy.array([['x1','y1']])
c = numpy.array([['x2','y2']])

我想创建一个字典:

d={'x': ['x1','x2'], 'y':['y1','y2']}

如何创建这样的字典?

最佳答案

如果你真的想要 d={'x':['x1','x2'],'y':['y1','y2']} 你可以去:

d = {i: [j, x] for i,j,x in zip(a,b,c)}

关于python - 在 Python 中从数组创建字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43208536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com