gpt4 book ai didi

python - 如何 reshape 列表数组?

转载 作者:太空宇宙 更新时间:2023-11-04 05:02:27 26 4
gpt4 key购买 nike

我有以下数组:

 array([ list(['4.224609607748e+00', '4.085857782359e+00', '1.273383604708e+00', '-6.802974691818e-03']),
list(['9.099528133406e-03', '6.867550219273e-03', '5.859231188647e-03', '3.684441849425e-03']),
list(['5.836775773317e-04', '-2.316776085880e-16', '-1.456850991492e-16', '-2.307897076406e-17']),
list(['4.140895678156e-03', '2.603906355541e-03', '4.125025757803e-04', '-1.739011495381e-03']),
list(['-1.681896173898e-03', '-5.241735641835e-04', '-1.739011375813e-03', '-1.681896058258e-03']), dtype=object)

我想对其进行修改,使其不再是一个包含 6 个列表的数组,而是一个形状为 (6,4) 的数组(即每个 float 都是数组中的一个元素)。我还想将 dtype 更改为 float(我不能这样做,因为它不会将列表识别为 float)。

我有办法做到这一点吗?

谢谢!

最佳答案

你只需要:

a = np.asarray([list(map(float, item)) for item in a])

关于python - 如何 reshape 列表数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45401482/

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