Ok guys! time to continue 🙂
In the last post I stop just before explaining how to allocate a tensor.
Allocate method
In the allocation method there is a line where the itertools.product command is used. It was the first time I saw such a command, so I opened reinteract (it’s like ipython) to test it.
import itertools
rank = (0,2)
n = rank[0] + rank[1]
indc = list(itertools.product(range(4),repeat=n))
indc
gives the output,
[(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3), (3, 0), (3, 1), (3, 2), (3, 3)]
Now I know!!! It gives you a list of the Cartesian product, i.e., a list of all possible values of the indices of a tensor of rank 🙂 Very clever Sergei!
Next there is a loop, which ends with an assignment. In the loop, every possible combination of indices is stored in a list called mastr and finally a dictionary is created by zipping this mastr list with a zeros list.
This loop assignment complication looks like a work around for differentiate upper and lower components. However, for my mental health… I’ll avoid (at least by now) the shape of the tensor, and the whole loop-assignment can be changed by,
self.components = dict(zip(indc,[0 for i in xrange(len(indc))]))
right after the Cartesian product definition.
_dictkeycopy Attribute
This attribute takes a dictionary (code name hay), extract the keys of the dictionary, and create a new dictionary with those keys but assigning zero values to every key.
:-S Got confused?
it’s like having a copy of the possible indices values of the tensor, zipped with zeros.
getNonZero attribute
This is another important attribute!!! We all know that not all components of tensor in GR are different than zero, so this attribute “print” only those that are non-vanishing 😉
I think it’s more or less clear what it does. It sweeps the values on the dictionary, and if the value is non-zero, it stores both key and value in a new dictionary 🙂
__str__ attribute
It prints the result of getNonZero. 😛
Now what?!
On the next post I’ll start by defining a metric tensor. However, it could be useful to define instead a set of vielbein and a signature… Perhaps later!
Get GR-module.py (version 2)
Got to work right now!
Enjoy life!
DOX
Leave a comment