Python matrix calculator for all matrix sizes