Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
也许这是一个简单的问题,但是有没有一种快速的方法来复制数组中的元素?对于 3D,它应该像这样工作:
1 2 3 4 5 6 7 8 9 1 1 2 2 3 3 1 1 2 2 3 3 4 4 5 5 6 6 4 4 5 5 6 6 7 7 8 8 9 9 7 7 8 8 9 9
我尝试了 3 个嵌套的 for 循环,但这真的很慢。
>>> a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> np.repeat(np.repeat(a, 2, 0), 2, 1) array([[1, 1, 2, 2, 3, 3], [1, 1, 2, 2, 3, 3], [4, 4, 5, 5, 6, 6], [4, 4, 5, 5, 6, 6], [7, 7, 8, 8, 9, 9], [7, 7, 8, 8, 9, 9]])