2 回答

TA贡献1827条经验 获得超9个赞
IIUC你可以这样做:
d = amask==False #First know which array values are masked
rows,columns = np.where(d) #Get the positions of row and column of masked values
rows.sort() #sort the row values
columns.sort() #sort the column values
print('Row values :',(rows[0],rows[-1])) #print the first and last rows
print('Column values :',(columns[0],columns[-1])) #print the first and last columns
Row values : (0, 4)
Column values : (1, 3)
或者
rows, columns = np.nonzero(~a.mask)
print('Row values :',(rows.min(), rows.max())) #print the min and max rows
print('Column values :',(columns.min(), columns.max())) #print the min and max columns
Row values : (0, 4)
Column values : (1, 3)

TA贡献1799条经验 获得超6个赞
这是一个基于argmax
-
# Get mask for any data along axis=0,1 separately
m0 = a.all(axis=0)
m1 = a.all(axis=1)
# Use argmax to get first and last non-zero indices along axis=0,1 separately
axis0_out = m1.argmax(), a.shape[0] - m1[::-1].argmax() - 1
axis1_out = m0.argmax(), a.shape[1] - m0[::-1].argmax() - 1
添加回答
举报