將數組擴展到特定大小的最有效方法是什麼?使用自己的內容將numpy數組擴展到特定範圍
import numpy as np
# For this example, lets use an array with 4 items
data = np.array([[0,1,2],[3,4,5],[6,7,8],[9,10,11]]) # 4 items
# I want to extend it to 10 items, here's the expected result would be:
data = np.array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11],
[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11],
[ 0, 1, 2],
[ 3, 4, 5]])
快速更正,你想要'arr [:fraction]'。根據數組的大小,您的方法可以明顯更快,因爲重複的整個*塊被中間存儲爲對同一對象的引用。 – Reti43
太棒了!是最後一項應該是arr [:fraction] – Fnord
已更正。改了名字,忘了其中的一個。 –