Investor Investor - 1 year ago 59
Python Question

How do I refer to the "return" of a function in a method from another class in Python?

Here is my code:

class MetricTensor: #The Metric Tensor Class
def __init__(self, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15): #Metric components
self.g0 = g0
self.g1 = g1
self.g2 = g2
self.g3 = g3
self.g4 = g4
self.g5 = g5
self.g6 = g6
self.g7 = g7
self.g8 = g8
self.g9 = g9
self.g10 = g10
self.g11 = g11
self.g12 = g12
self.g13 = g13
self.g14 = g14
self.g15 = g15

def LMetric(self):
lmetric = [self.g0, self.g1, self.g2, self.g3, self.g4, self.g5, self.g6, self.g7, self.g8, self.g9, self.g10, self.g11, self.g12, self.g13, self.g14, self.g15]
return list(lmetric)

def Mmetric(self,lmetric):
mmetric = np.matrix([lmetric[0],lmetric[1],lmetric[2],lmetric[3], [lmetric[4],lmetric[5],lmetric[6],lmetric[7]], [lmetric[8],lmetric[9],lmetric[10],lmetric[11]], [lmetric[12],lmetric[13],lmetric[14]],lmetric[15]])
return mmetric

def InvMmetric(self,mmetric):
invmmetric =
return invmmetric
def LInvMetric(self,invmmetric):
linvmetric = list(invmmetric)
return linvmetric

class ChristoffelSymbol(MetricTensor):
def __init__(self,a, b, c):
self.a = a
self.b = b
self.c = c
Ca = None
for k in numcoords:
Ca += 1/2*(linvmetric)

Notice the last method of the MetricTensor class: LInvmetric, this function returns : linvmetric.

My question is:
How do I use this return (linvmetric) in a new class (ChristoffelSymbol), that is a subclass of the first (MetricTensor)?

More accurately, how do I only use one element in linvmetric (since it is a list, I want to use linvmetric[0], for example)?

Answer Source

Updated answer after some discussion:

You will also need to call the methods that you have defined in the MetricTensor class. The code below does this:

mt = MetricTensor("...args...")  # args here are all the metric components
lmetric = mt.LMetric()
mmetric = mt.Mmetric(lmetric)
invmmetric = mt.InvMmetric(mmetric)
linvmetric = mt.LInvMetric(invmetric)

Now linvmetric can be used in further code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download