№ 1
The focus on finding the third is to subtract from 3
those maximum and minimum indices. The borderline case would be when the indices max and min coincide, i.e. All three elements along the last axis are the same, for which the index of the third element will also be the same.
So we will have one solution:
max_idx = y.argmax(2)
min_idx = y.argmin(2)
rem_idx = np.where(max_idx == min_idx, max_idx, 3 - max_idx - min_idx)
out = (y[all_idx(max_idx, 2)] -2*y[all_idx(min_idx, 2)])/y[all_idx(rem_idx, 2)]
Helper function for indexing in y
with indexes -
def all_idx(idx, axis):
grid = np.ogrid[tuple(map(slice, idx.shape))]
grid.insert(axis, idx)
return tuple(grid)
Approach # 2
We could get the summation along the axis and subtract the min and max values to get the third element and just connect this to the formula -
maxv = np.max(y, axis =2)
minv = np.min(y, axis =2)
x = (maxv - 2*minv)/(y.sum(2) - maxv - minv)
source
share