This guide is obsolete, it was written during the early stages when I was learning python. A more up to date guide is available here:
Other python guides including installation of python are available in:
Array Division of Square Matrices Using the Inverse
Lets create the following two matrices and multiply them using the dot product to get C:
[[19 22]
[43 50]]
Matrix Division is always gently brushed over at school with only the special case of a 2 by 2 square matrix being solved using the inverse of the square matrix.
For:
With AInv, the Inverse Matrix of A is defined as:
Substituting in the numbers:
In Python to find the Inv Matrix we can use the function inv in the linear algebra (linalg) section of the numpy library:
[[2. 1. ]
[ 1.5 0.5]]
Now when a Matrix is multiplied by it's inverse will give the Identity matrix I:
Lets check this in Python:
[[1.0000000e+00 4.4408921e16]
[0.0000000e+00 1.0000000e+00]]
[[1.00000000e+00 1.11022302e16]
[0.00000000e+00 1.00000000e+00]]
The numbers in the antidiagonal are effectively zero, showing only to the 16th decimal place. We could use np.round to round to 5 decimal places:
[[1. 0.]
[0. 1.]]
If we multiply the expression
[[1. 0.]
[0. 1.]]
Throughout by the inverse of A:
When a Matrix is multiplied by the Identity Matrix it is unchanged
We can check this in Python using:
[[5. 6.]
[7. 8.]]
[[5. 6.]
[7. 8.]]
Therefore:
Becomes:
This gives the correct value of B. Lets check this in Python:
[[5. 6.]
[7. 8.]]
This can be thought of as:
Assuming we don't know the values of B, but we know the values of A and C. This is 4 sets of equations, containing 4 unknowns:

B(1,1)+2⁕B(2,1)=19<br>

B(1,2)+2⁕B(2,2)=22<br>

3⁕B(1,1)+4⁕B(2,1)=43<br>

3⁕B(1,2)+4⁕B(2,2)=50
Rearranging 1:
Substituting into 3:
Substituting this into 1 (which was rearranged):
Now rearranging 2:
Now substituting into 4:
Substituting this into the rearranged 2:
This gives:
As expected.
Square Matrix Division
Python can perform Matrix Division using the least squares function solve which carries out matrix division using the inverse and hence requires a square matrice or lstsq of the linear algebra library which uses least squares to find the coefficients. Note I have found that NumPy's lstsq method to be substantially inferior to MATLAB/Octave.
Let's look at the case:
Solving for B we get
[[5. 6.]
[7. 8.]]
[[5. 6.]
[7. 8.]]
[]
2
[5.4649857 0.36596619]
Starting with:
$latex \displaystyle \frac{1}{A}AB=\frac{1}{A}*C$
To find B opposed to A it is slightly different:
$latex \displaystyle AB\frac{1}{B}=C*\frac{1}{B}$
This gives us the same form we used previously but with both sides as Transposes.
[[1. 3.]
[2. 4.]]
[[1. 3.]
[2. 4.]]
[]
2
[5.4649857 0.36596619]
We can then Transpose the result:
[[1. 2.]
[3. 4.]]
NonSquare Matrix Division
We can use the data we multiplied together to work back from to illustrate division:
Assuming we know S and A and want to calculate E:
array([[ 3, 5, 4],
[15, 25, 20],
[ 3, 5, 4],
[ 6, 10, 8]])
[[0.06 0.1 0.08]]
[[0.03225806]
[0.16129032]
[0.03225806]
[0.06451613]]
Here the results are not precisely as expected. S1 is S*1/50 and E1 is approximately E*1/31.