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

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!