TLabels = np.array([-1, 1, 1, 1, 1, -1, -1, 1, -1, -1])
t = len(dist)
dist_zeros = dist_ == 0
one_zero_sum = [sum(TLabels[dist_zeros]) / t, sum(TLabels[~dist_zeros]) / t]
cLoss = sum([(1 - x * one_zero_sum[dist_[y]]) for y, x in enumerate(TLabels)])
NumPy: How to avoid this loop?