3 回答

TA貢獻1793條經驗 獲得超6個贊
This should do the trick
Y = 961
X = 832
all_ = np.random.rand(832*961)
# Iterating over the values of y
for i in range(1,Y):
# getting the indicies from the array we need
# i - 1 = Start
# X*i = END
# 2 is the step
indicies = list(range(i-1,X*i,2))
# np.take slice values from the array or get values corresponding to the list of indicies we prepared above
required_array = np.take(indices=indices)

TA貢獻1804條經驗 獲得超2個贊
假設您有一個形狀數組(x * y,),想要分塊處理x。您可以簡單地重新調整數組的形狀來調整(y, x)和處理行:
>>> x = 832
>>> y = 961
>>> arr = np.arange(x * y)
現在重塑并批量處理。在下面的示例中,我取每行的平均值。您可以通過這種方式將任何您想要的函數應用于整個數組:
>>> arr = arr.reshape(y, x)
>>> np.mean(arr[:, ::2], axis=1)
>>> np.mean(arr[:, 1::2], axis=1)
重塑操作不會更改數組中的數據。它指向的緩沖區與原始緩沖區相同。ravel您可以通過調用數組來反轉重塑。

TA貢獻1851條經驗 獲得超4個贊
對于對此解決方案感興趣的任何人(每次迭代,而不是每次迭代增加移位):
for i in range(Y):
shift = X * (i // 2)
begin = (i % 2) + shift
end = X + shift
print(f'{begin}:{end}:2')
添加回答
舉報