Question: Im trying to solve a matrix where: a= [[2 0], [0 2], [1 1]] b= [[0], [0], [0]] I am using numpy to solve this
![Im trying to solve a matrix where: a= [[2 0], [0](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f303bd0d09e_23766f303bd08979.jpg)
Im trying to solve a matrix where:
a= [[2 0], [0 2], [1 1]]
b= [[0], [0], [0]]
I am using numpy to solve this matrix. The matrix is supposed to balance a chemical equation in this case it is H2 + O2 ---> H2O
My main error is last 2 dimensions of the array must be square
Traceback (most recent call last): File "/Users/parsa/Desktop/A2/Reactiont.py", line 152, in bal = balance(lhsList, rhsList), File "/Users/parsa/Desktop/A2/Reactiont.py", line 108, in balance x = lin.solve(a,b) File "<_array_function_ internals>", line 6, in solve File "/usr/local/Cellar/python/3.7.3/Frameworks/Python. framework/Versions/3.77 lib/python3.7 site-packagesumpy _assert_stacked_square(a) File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packagesumpy/ raise LinAlgError('Last 2 dimensions of the array must be square'), numpy. linalg.LinAlgError: Last 2 dimensions of the array must be square Traceback (most recent call last): File "/Users/parsa/Desktop/A2/Reactiont.py", line 152, in bal = balance(lhsList, rhsList), File "/Users/parsa/Desktop/A2/Reactiont.py", line 108, in balance x = lin.solve(a,b) File "<_array_function_ internals>", line 6, in solve File "/usr/local/Cellar/python/3.7.3/Frameworks/Python. framework/Versions/3.77 lib/python3.7 site-packagesumpy _assert_stacked_square(a) File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packagesumpy/ raise LinAlgError('Last 2 dimensions of the array must be square'), numpy. linalg.LinAlgError: Last 2 dimensions of the array must be square