python - 复制列表中的对象以使其重复
问题描述
如何复制列表中的元素以使它们重复?
Input: ListA = [1,2,3,4,5,6,7,8,9]
Output: ListA = [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9]
解决方案
我们可以用np.repeat()
ListA = [1,2,3,4,5,6,7,8,9]
ListA = np.repeat([1,2,3,4,5,6,7,8,9], 2)
ListA
输出
array([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9])
推荐阅读
- react-native - OrbitControls 无法正常工作
- expo - Fastlane 从 Expo 构建 URL 向 TestFlight 提供 .ipa 文件
- aws-lambda - 在 Quarkus Amazon Lambda HTTP 指南中,Lambda 运行时在类路径上找不到 QuarkusStreamHandler
- java - 在测试失败时,WebDriverEventListener 的方法“beforeGetScreenshotAs”会持续运行。这种方法的最佳实现是什么?
- deep-learning - 在 Google Colab 的 pytorch 下使 CUDA 内存不足
- ios - iOS SwiftUI:从父级到子级的 ObservableObject
- vb.net - DataGridView中的组合框如何填充第二列中的另一个组合框
- maven - “maven.compiler.release”作为源和目标的替代品?
- java - VisualVM 工具中的反向呼叫和前向呼叫
- sql - Oracle SQL 实时选择并连接数百万条记录的表