Matrix multiplication in C++ and Python