I need to optimize my code and have been able to remove for loops almost everywhere but struggle for this small part. I\'ve looked at numpy.where but don\'t think I can use