Numpy Apply Function To Each Element Of Matrix