On Thu, Aug 13, 2020 at 11:17:00PM +0100, Stefano Borini wrote:
The math module has plenty of mathematical functions that are very interesting, but no Matrix object.
Funny you mention this, I have been working on a Matrix object for precisely the use-case you discuss (secondary school maths), where performance is not critical and the dimensions of the matrix is typically single digits.
I, um, got distracted with some over-engineering and then distracted further by work and life, but perhaps this is a good opportunity for me to get it back on track.
Generally, when a Matrix object is needed, numpy is the point of reference, but numpy requires understanding pip, installing modules, maybe creating a virtual environment and finally understanding numpy.
And numpy also offers a surprising interface that doesn't match matrices. (Well, surprising to those who aren't heavy users of numpy :-)
py> A = numpy.array([[1, 2], [3, 4]]) py> A*A array([[ 1, 4], [ 9, 16]])
To get *matrix multiplication* you have to use the `@` multiplication operator from PEP 465:
py> A@A array([[ 7, 10], [15, 22]])
https://www.python.org/dev/peps/pep-0465/
But what's really surprising about numpy arrays is broadcasting:
py> A = numpy.array([[1, 2], [3, 4]]) py> B = numpy.array([[10, 20]]) py> A + B array([[11, 22], [13, 24]])
I don't know if broadcasting is actually useful or not, but it's not what you want when doing matrix arithmetic at a secondary school level.