我有一个名为formattedData
的numpy数组,它有大约1000行,当前设置为包含:
-999 -999 -999
-999 -999 -999
...
-999 -999 -999
我有另一个变量timeList
,它是一个长度为5:的列表
1
2
3
4
5
我想用timeList
中的数据覆盖formattedData
中的第三列,这些数据一遍又一遍地重复,直到数组结束。我知道timeList
将始终与formattedData
匹配精确的次数,例如:
-999 -999 1
-999 -999 2
-999 -999 3
-999 -999 4
-999 -999 5
-999 -999 1
-999 -999 2
-999 -999 3
-999 -999 4
-999 -999 5
...
-999 -999 1
-999 -999 2
-999 -999 3
-999 -999 4
-999 -999 5
我试过各种各样的方法,但都没能奏效。有人能帮我指出正确的方向吗?
谢谢!
您可以使用np.tile
来重复您的列表,然后将其放入数组的第三列。重复次数已预先计算:
num_repeats = len(formattedData) // len(timeList)
to_place = np.tile(timeList, reps=num_repeats)
formattedData[:, 2] = to_place
TRY:
formatteddata[:, 2] = np.tile(
timelist, formatteddata.shape[0] // timelist.shape[0])