今天早些时候我问
this
关于整数数组索引,我很难找到答案并将其应用到激发问题的问题上。
p_stack1
和
c_stack1
堆垛1
包含概率数据和
c U堆叠1
包含整数分类。我需要找到在768x 1024尺寸的图像中每个像素的概率最高的分类。从文件中
integer array indexing
我最初问题的解决方案适用于nxnxn形阵列的简化示例,但似乎不适用于lxmxn形阵列。
#dummy data
p_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 0
ind_new=p_stack1.argmax(axis=0)
#Create assending indicies
nx, ny = 768,1024
xx = 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 indexing
print(c_stack1[ind_new, aa,bb])
最后一个print语句返回错误:
IndexError: index 768 is out of bounds for axis 1 with size 768
aa
和
bb
(768, 1024)
我错过了什么?