def get_centerline(data, dim):
    centerline = np.zeros(dim)

    data[data == np.inf] = 0
    data[data == np.nan] = 0

    for iz in range(0, dim[2]):
        ind = np.argmax(data[:, :, iz])
        X, Y = ind2sub(data[:, :, iz].shape,ind)
        centerline[X,Y,iz] = 1

    return centerline
Convert the TopK operation to a table aggregation
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/sct_detect_spinalcord/sct_detect_spinalcord.py/get_centerline--crossover with--dataset/ETHPy150Open cloudera/ibis/ibis/expr/operations.py/TopKExpr.to_aggregation