Fix Sympy Not Working: TypeError

  • Thread starter Thread starter ergospherical
  • Start date Start date
AI Thread Summary
The discussion addresses a TypeError encountered in Python when using the SymPy library to create a matrix. The error message indicates that the input data type is not understood, specifically expecting a "list of lists" or "lists of values." To resolve this, the correct format for creating a matrix with SymPy is demonstrated by using a nested list structure. The example provided shows how to define a matrix 'g' using the appropriate syntax: g = sp.Matrix([[g00,g01,g02,g03],[g10,g11,g12,g13],[g20,g21,g22,g23],[g30,g31,g32,g33]]). The discussion highlights the importance of using this format to avoid errors and suggests that while SymPy matrices can be cumbersome, alternatives like numpy.ndarray may offer a more user-friendly experience.
ergospherical
Science Advisor
Homework Helper
Education Advisor
Insights Author
Messages
1,100
Reaction score
1,387
Computer says "TypeError: Data type not understood; expecting list of lists or lists of values."

Python:
import sympy as sp

t,r,a,b = sp.symbols('t r a b')

g00 = -(1-(1/r))
g01 = 0
g02 = 0
g03 = 0
g10 = 0
g11 = 1/(1-(1/r))
g12 = 0
g13 = 0
g20 = 0
g21 = 0
g22 = r**2
g23 = 0
g30 = 0
g31 = 0
g32 = 0
g33 = (r**2)*((sp.sin(a))**2)

g = sp.Matrix([g00,g01,g02,g03],[g10,g11,g12,g13],[g20,g21,g22,g23],[g30,g31,g32,g33])
print(g)
 
Technology news on Phys.org
Make a list as a variable named “glist”

and then use it as the argument to Matrix

find an example online using sp.Matrix as a reference.
 
  • Like
Likes ergospherical
You just need to make the Matrix input a nested list, like this:
Python:
g = sp.Matrix([[g00,g01,g02,g03],[g10,g11,g12,g13],[g20,g21,g22,g23],[g30,g31,g32,g33]])

This is what the error message means when it says a "list of lists".
 
  • Like
Likes sysprog, ergospherical and pbuk
Aah the old list of lists trick -- Maxwell Smart of Get Smart!
 
Matrices as lists of lists are horrible, numpy.ndarray is much nicer.
 
  • Like
Likes jim mcnamara and jedishrfu
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...

Similar threads

Replies
9
Views
4K
Replies
15
Views
4K
Back
Top