附加不同大小的数组 python
Appending arrays of different sizes python
我想附加以下不同大小的数组,这些数组是在 for 循环内部附加的结果,这样所有数组元素都存储在一列中:
s =[array([ 81.0156 , 94.8436 , 108.6716 , 122.4996 ,
136.6136 , 150.4416 , 164.2696 , 178.0976 ,
191.9256 , 370.2036 , 384.0316 , 397.8596 ,
411.6876 , 425.5156 , 439.6296 , 453.4576 ,
467.2856 , 481.1136 , 643.8476 , 657.6756 ,
671.5036 , 685.3316 , 699.4456 , 713.2736 ,
727.1016 , 740.9296 , 754.7576 , 990.34984648,
1004.46384648, 1018.29184648, 1032.11984648, 1045.94784648,
1562.33409302, 1576.44809302, 1590.27609302, 1604.10409302,
1617.93209302, 1780.66609302, 1794.49409302, 1808.32209302,
1822.15009302, 1836.26409302, 1850.09209302, 1863.92009302,
1877.74809302, 1891.57609302, 2069.85409302, 2083.68209302,
2097.51009302, 2111.33809302, 2125.16609302, 2139.28009302,
2153.10809302, 2166.93609302, 2180.76409302]),
array([ 74.1016 , 87.9296 , 101.7576 , 115.5856 ,
129.4136 , 143.5276 , 157.3556 , 171.1836 ,
185.0116 , 377.1176 , 390.9456 , 404.7736 ,
418.6016 , 432.7156 , 446.5436 , 460.3716 ,
474.1996 , 488.0276 , 636.9336 , 650.7616 ,
664.5896 , 678.4176 , 692.2456 , 706.3596 ,
720.1876 , 734.0156 , 747.8436 , 983.43584648,
997.54984648, 1011.37784648, 1025.20584648, 1039.03384648,
1052.86184648, 1555.13409302, 1569.53409302, 1583.36209302,
1597.19009302, 1611.01809302, 1624.84609302, 1773.75209302,
1787.58009302, 1801.40809302, 1815.23609302, 1829.06409302,
1843.17809302, 1857.00609302, 1870.83409302, 1884.66209302,
2076.76809302, 2090.59609302, 2104.42409302, 2118.25209302,
2132.36609302, 2146.19409302, 2160.02209302, 2173.85009302,
2187.67809302]),
array(769.4983),
array(783.9523),
array(961.88654658),
array(976.00054658),
array(1074.80254648),
array(1060.68514648),
array(1533.58479302),
array(1547.69879302),
array(206.6663),
array(221.1203),
array(341.4003),
array(355.8543),
array(1946.70719302),
array(1953.62519302),
array(2007.46519302),
array(2014.38319302)]
我尝试了以下方法:
s2 = sorted(numpy.concatenate(s))
但是我得到了错误消息:
all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 2 has 0 dimension(s)
我也尝试过使用:np.column_stack(s) 但它也不起作用。
在连接之前展平每个元素
sorted(np.concatenate([x.flatten() for x in s]))
您也可以使用 sorted(np.block(s))
进行递归连接。
我想附加以下不同大小的数组,这些数组是在 for 循环内部附加的结果,这样所有数组元素都存储在一列中:
s =[array([ 81.0156 , 94.8436 , 108.6716 , 122.4996 ,
136.6136 , 150.4416 , 164.2696 , 178.0976 ,
191.9256 , 370.2036 , 384.0316 , 397.8596 ,
411.6876 , 425.5156 , 439.6296 , 453.4576 ,
467.2856 , 481.1136 , 643.8476 , 657.6756 ,
671.5036 , 685.3316 , 699.4456 , 713.2736 ,
727.1016 , 740.9296 , 754.7576 , 990.34984648,
1004.46384648, 1018.29184648, 1032.11984648, 1045.94784648,
1562.33409302, 1576.44809302, 1590.27609302, 1604.10409302,
1617.93209302, 1780.66609302, 1794.49409302, 1808.32209302,
1822.15009302, 1836.26409302, 1850.09209302, 1863.92009302,
1877.74809302, 1891.57609302, 2069.85409302, 2083.68209302,
2097.51009302, 2111.33809302, 2125.16609302, 2139.28009302,
2153.10809302, 2166.93609302, 2180.76409302]),
array([ 74.1016 , 87.9296 , 101.7576 , 115.5856 ,
129.4136 , 143.5276 , 157.3556 , 171.1836 ,
185.0116 , 377.1176 , 390.9456 , 404.7736 ,
418.6016 , 432.7156 , 446.5436 , 460.3716 ,
474.1996 , 488.0276 , 636.9336 , 650.7616 ,
664.5896 , 678.4176 , 692.2456 , 706.3596 ,
720.1876 , 734.0156 , 747.8436 , 983.43584648,
997.54984648, 1011.37784648, 1025.20584648, 1039.03384648,
1052.86184648, 1555.13409302, 1569.53409302, 1583.36209302,
1597.19009302, 1611.01809302, 1624.84609302, 1773.75209302,
1787.58009302, 1801.40809302, 1815.23609302, 1829.06409302,
1843.17809302, 1857.00609302, 1870.83409302, 1884.66209302,
2076.76809302, 2090.59609302, 2104.42409302, 2118.25209302,
2132.36609302, 2146.19409302, 2160.02209302, 2173.85009302,
2187.67809302]),
array(769.4983),
array(783.9523),
array(961.88654658),
array(976.00054658),
array(1074.80254648),
array(1060.68514648),
array(1533.58479302),
array(1547.69879302),
array(206.6663),
array(221.1203),
array(341.4003),
array(355.8543),
array(1946.70719302),
array(1953.62519302),
array(2007.46519302),
array(2014.38319302)]
我尝试了以下方法:
s2 = sorted(numpy.concatenate(s))
但是我得到了错误消息:
all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 2 has 0 dimension(s)
我也尝试过使用:np.column_stack(s) 但它也不起作用。
在连接之前展平每个元素
sorted(np.concatenate([x.flatten() for x in s]))
您也可以使用 sorted(np.block(s))
进行递归连接。