目前我有一个数组列表如下:
array =
[array([100000. , 100848.06652142, 99648.67144694, 102047.67944271,
103655.99048427, 104602.87678005, 104597.83419837, 103505.42736768,
104976.01311214, 104457.34603404, 105855.46549162, 105613.30235519,
105212.71840922, 107647.5054673 ])
array([107647.5054673 , 106891.82007643, 106979.91405552, 106030.74186486,
107856.04281712, 108502.71948581, 106557.2401056 , 105659.59829843,
105663.01875745, 107300.69453018, 106336.34733019, 107584.99034227,
108089.2320392 , 106786.91702337])
array([106786.91702337, 104416.74000465, 101289.12525402, 101932.58219813,
102625.04352578, 101767.46209616, 103345.4263012 , 102816.73322055,
102417.59316407, 104439.37518975, 103755.22627215, 103817.9744686 ,
107872.40234863, 108110.9662065 ])
array([108110.9662065 , 109544.86827069, 111072.22392645, 112618.46235766,
113847.1768898 , 116708.86391903, 115790.02599715, 115614.72242411,
119225.88436354, 121991.38468934, 123304.85972848, 125571.38040251,
122456.3667249 ])
array([122456.3667249 , 127497.74699282, 128659.85495604, 125813.77115906,
129008.46450085, 128111.00914756, 123039.92607546, 124723.87932757,
124181.57385836, 125134.9276196 , 126027.8631434 , 129304.85119148,
128912.58600657])]
将所有这些子阵列重新组合成一个大型阵列的最佳方法是什么?我试过了np.concatenate()
但是没有用。
解
无论出于何种原因,一旦我能够找到np.concatenate()
确实有效的修复,我的输出就不会在子数组之间放置逗号。
答案 0 :(得分:2)
连接工作..我想你在列表中的每个数组之间的示例数据中忘记了一些逗号。
import numpy as np
a = [np.array([1,2,3]), np.array(['4','5','6'])]
np.concatenate(a)
输出
array(['1', '2', '3', '4', '5', '6']
答案 1 :(得分:1)
np.concatenate(array)
唯一的问题,在您的示例中,列表array
中的array
(现在,您认为使用令人困惑的名称有多糟糕)应该成为np.array
并且您应该添加列表numpy.ndarray
中每个array
后面的逗号:
array = [np.array([100000., 100848.06652142, 99648.67144694, 102047.67944271,
103655.99048427, 104602.87678005, 104597.83419837, 103505.42736768,
104976.01311214, 104457.34603404, 105855.46549162, 105613.30235519,
105212.71840922, 107647.5054673 ]),
np.array([107647.5054673 , 106891.82007643, 106979.91405552, 106030.74186486,
107856.04281712, 108502.71948581, 106557.2401056 , 105659.59829843,
105663.01875745, 107300.69453018, 106336.34733019, 107584.99034227,
108089.2320392 , 106786.91702337]),
np.array([106786.91702337, 104416.74000465, 101289.12525402, 101932.58219813,
102625.04352578, 101767.46209616, 103345.4263012 , 102816.73322055,
102417.59316407, 104439.37518975, 103755.22627215, 103817.9744686 ,
107872.40234863, 108110.9662065 ]),
np.array([108110.9662065 , 109544.86827069, 111072.22392645, 112618.46235766,
113847.1768898 , 116708.86391903, 115790.02599715, 115614.72242411,
119225.88436354, 121991.38468934, 123304.85972848, 125571.38040251,
122456.3667249 ]),
np.array([122456.3667249 , 127497.74699282, 128659.85495604, 125813.77115906,
129008.46450085, 128111.00914756, 123039.92607546, 124723.87932757,
124181.57385836, 125134.9276196 , 126027.8631434 , 129304.85119148,
128912.58600657])]