我将以下面描述的方式在多维数组上附加一个for循环。但是,输出不是所需的。所需的输出是一个由多个5D阵列组成的阵列。
import numpy as np
series_1 = [
[0. 0. 0. 0. 0.],
[0. 0. 0. 0. 0.],
[0. 0. 0. 0. 0.]]
series_2 = [
[0. 1. 0. 0. 0. ],
[0. 0.5 0.5 0. 0. ],
[0. 1. 0. 0. 0. ],
[0. 0. 1. 0. 0. ]]
series_3 = [
[1. 0. 0. 0. 0. ],
[0.5 0. 0. 0. 0. ],
[1. 0. 0. 0. 0. ],
[1. 0. 0. 0. 0. ],
[0. 0. 0. 1. 0. ]]
phases = [1, 2, 3]
average_total = []
for phase in phases:
if phase == 1:
average_series_T = series_1
elif phase == 2:
average_series_T = series_2
elif phase == 3:
average_series_T = series_3
# add each phase to the total sequence
average_total.append(average_series_T)
print("average total:")
print(average_total)
输出:
[array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]]), array([[0. , 1. , 0. , 0. , 0. ],
[0. , 0.5, 0.5, 0. , 0. ],
[0. , 1. , 0. , 0. , 0. ],
[0. , 0. , 1. , 0. , 0. ]]), array([[1. , 0. , 0. , 0. , 0. ],
[0.5, 0. , 0. , 0. , 0. ],
[1. , 0. , 0. , 0. , 0. ],
[1. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 1. , 0. ]])]
但是,我希望输出为:
[
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0. , 1. , 0. , 0. , 0. ],
[0. , 0.5, 0.5, 0. , 0. ],
[0. , 1. , 0. , 0. , 0. ],
[0. , 0. , 1. , 0. , 0. ],
[1. , 0. , 0. , 0. , 0. ],
[0.5, 0. , 0. , 0. , 0. ],
[1. , 0. , 0. , 0. , 0. ],
[1. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 1. , 0. ],
]
我希望输出是5D数组的数组,但是Pandas DataFrame或类似的东西也可以使用。我基本上想将series_1 series_2和series_3放到一个形状为(x,5)的对象中,其中x是5D数组的数量。
是您想要的吗?
L_arrays=[serie_1]
L_arrays.append(serie_2)
L_arrays.append(serie_3)
result = []
for i in range(len(L_arrays)):
for row in L_arrays[i]:
result.append(row)
print(array(result))