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]])