【发布时间】:2019-08-01 13:51:27
【问题描述】:
我想扩充列表来自
[1, 2, 3, 4, 5]
到
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
如果我想同样增加 n 次(比如 100 或 500 次),我该怎么做?我不想用常规循环来做,而是使用像 numpy 这样的库。有什么帮助吗?
非常感谢。
【问题讨论】:
-
你想要列表中的每个数字两次
-
只有 itertools 你可以做到
list(chain.from_iterable(repeat(x, 2) for x in a))。 -
user3483203 将我的问题标记为重复,答案就是我想知道的。 yatu也回答了我的问题;谢谢大家。
标签: python list numpy data-augmentation