今天早些時候,我問了有關整數數組索引的問題,我在獲取答案并將其應用于啟發問題的問題上遇到了麻煩。簡而言之,p_stack1它c_stack1包含從我正在研究的圖像處理算法派生的數組。 p_stack1包含概率數據并c_stack1包含整數分類。我需要找到尺寸為768 x 1024的圖像中每個像素的概率最高的分類。從用于整數數組索引的文檔中,它提供了一種使用其整數索引對較高維數組的數據進行子集化的方法。我最初提出的問題的解決方案適用于nxnxn形狀的數組的簡化示例,但似乎不適用于lxmxn形狀的數組。#dummy datap_stack1 = np.reshape(np.random.uniform(0,1,2359296),(3,768,1024))c_stack1 = np.reshape(np.random.randint(0,4,2359296),(3,768,1024))#find where max value occurs on axis 0ind_new=p_stack1.argmax(axis=0)#Create assending indiciesnx, ny = 768,1024xx = np.arange(ny)aa= np.tile(xx,(ny,1))bb = np.column_stack(tuple(aa))[:nx,:]aa= np.tile(xx,(ny,1))[:nx,:]#perform the integer array indexingprint(c_stack1[ind_new, aa,bb])最后的打印語句返回錯誤:IndexError: index 768 is out of bounds for axis 1 with size 768我檢查了aa和的形狀,bb兩者都是(768, 1024)我錯過了什么?
添加回答
舉報
0/150
提交
取消