changing coefficients calculation to use numpy ndarrays