There is no need to calculate the distance in a quadratic form by generating the diagonal matrix intermediately. Just arranging the weights as a vector and calculating the linear combination solves the calculation. This also reduces the overhead of computation because after the modification, only one matrix product need to be calculated.
There is no need to calculate the distance in a quadratic form by generating the diagonal matrix intermediately. Just arranging the weights as a vector and calculating the linear combination solves the calculation. This also reduces the overhead of computation because after the modification, only one matrix product need to be calculated.