You don't necessarily have to roll your own matrix class, there are a number of them out there already. If you're doing a lot of numerical work, you might like
for elementwise multiplication). If you're doing exclusively 3d work, you might want something specialized for that purpose, but I don't have a module to suggest.