There are only a few programming languages that have nontrivial matrix operations as
built-in functionality, and those that do (like Matlab and Mathematica) tend to be awkward for general-purpose (i.e., non-mathematical) programming. The preferred approach in general-purpose languages is to leave matrices and matrix arithmetic to third-party libraries.
In Python, you have multiple options:
- use a list of lists. You'll have to code your own matrix operations, and it won't be very efficient.
- use
NumPy, which I highly recommend. This gives you not only two-dimensional arrays, but arrays of arbitrary dimensionality. You also get all the standard matrix operations, including multiplication. The newest version of NumPy also includes the very useful
einsum function, which is a generalization of matrix multiplication. (For example, this allows you to matrix-multiply one array of matrices elementwise against another array of matrices in one line of code.)
- use another third-party library that implements some matrix functionality. I don't know of any that are as powerful as NumPy.