小编As *_*ent的帖子

如何复制列表/数组中的特定值?

关于如何在Python中重复数组中某个值的任何建议?例如,我想只重复2次array_a:

array_a = [1, 2, 1, 2, 1, 1, 2]
Run Code Online (Sandbox Code Playgroud)

想要的结果是:我重复每一个2并离开1:

array_a = [1, 2, 2, 1, 2, 2, 1, 1, 2, 2]  # only the `2` should be repeated
Run Code Online (Sandbox Code Playgroud)

我试过numpy,我可以复制整个数组,但不是一定的值.

python arrays numpy list numpy-ndarray

7
推荐指数
1
解决办法
158
查看次数

标签 统计

arrays ×1

list ×1

numpy ×1

numpy-ndarray ×1

python ×1