在数据处理期间,我创建一个如下所示的数组:
[array([ 0.08606408]) array([ 0.26071976])
array([ 0.181566 , 0.94154611]) array([ 0.1734347 , 0.94160601])
array([ 0.17859844, 0.94167483]) array([ 0.16880761, 0.94156277])
array([ 0.17624151, 0.94149038]) array([ 0.18770433, 0.94181287])
array([ 0.16707977, 0.94227733]) array([ 0.94162233])
array([ 0.9426902, 0.9615621]) array([ 0.94195127, 0.96174422])
array([ 0.94237795, 0.96195226, 0.98059446])
array([ 0.94249657, 0.96219391, 0.98095329])
array([ 0.94280697, 0.96286183, 0.98109352])
array([ 0.94267473, 0.96304417, 0.98252799])]
以下列方式创建:
peakpositions = []
peakpositions.append(stuff)
如何将浮点值提取到单个1D numpy数组中? 我想要的是这个:
[0.08606408, 0.26071976, 0.181566 ... 0.98252799]
提前致谢!
答案 0 :(得分:4)
您可以连接内部数组:
peakpositions=np.concatenate(peakpositions)
演示:
>>> l= [[array([ 0.08606408]), array([ 0.26071976]),
array([ 0.181566 , 0.94154611]),
array([ 0.1734347 , 0.94160601]),
array([ 0.17859844, 0.94167483]),
array([ 0.16880761, 0.94156277]),
array([ 0.17624151, 0.94149038]),
array([ 0.18770433, 0.94181287]),
array([ 0.16707977, 0.94227733]), array([ 0.94162233]),
array([ 0.9426902, 0.9615621]), array([ 0.94195127, 0.96174422]),
array([ 0.94237795, 0.96195226, 0.98059446]),
array([ 0.94249657, 0.96219391, 0.98095329]),
array([ 0.94280697, 0.96286183, 0.98109352]),
array([ 0.94267473, 0.96304417, 0.98252799])]
>>> np.concatenate(l)
array([ 0.08606408, 0.26071976, 0.181566 , 0.94154611, 0.1734347 ,
0.94160601, 0.17859844, 0.94167483, 0.16880761, 0.94156277,
0.17624151, 0.94149038, 0.18770433, 0.94181287, 0.16707977,
0.94227733, 0.94162233, 0.9426902 , 0.9615621 , 0.94195127,
0.96174422, 0.94237795, 0.96195226, 0.98059446, 0.94249657,
0.96219391, 0.98095329, 0.94280697, 0.96286183, 0.98109352,
0.94267473, 0.96304417, 0.98252799])
>>>
答案 1 :(得分:0)
创建一个空列表/数组并对其进行扩展。
array_1d = []
for array in arrays:
array_1d.extend(array)
那应该是神奇的。