0
$\begingroup$

I am a quantum physics researcher but till now I have been using Mathematica symbolic language for solving quantum problems. I wanted to develop numerical skills as well so I just started to learn QuTip. I am ok at Python and need help occasionally with some concepts. So here is where I am stuck right now:

def sim_transform(old1, old2, new1, new2): 
#Form the similarity transform from one basis to another.
# Calculate the relevant inner products:
a = new1.dag()*old1 
b = new1.dag()*old2 
c = new2.dag()*old1 
d = new2.dag()*old2 

# extract values from these Qobj inner # product results, reshape to 2 by 2, and # form a new Qobj matrix: 
s = [i.data[0,0] for i in [a,b,c,d]]
return Qobj(array(s).reshape(2,2))

In the above function, can someone please explain to me what do last two lines do? I don't understand what data, i.data, array(s).reshape(2,2) do. Thank you in advance.

$\endgroup$

1 Answer 1

0
$\begingroup$

This expression

s = [i.data[0,0] for i in [a,b,c,d]]

is a standard Python loop comprehension iterating over the set [a, b, c, d] (which represent the variables (arrays?) above). It appears to generate a list containing the elements [0,0] from each of the arrays a, b, c, d.

I suspect that the reshape is modelled after numpy's reshape (link). In the example, a $1 \times 4$ vector is being converted to a $2 \times 2$ matrix: $$ [ a, b, c, d ] \rightarrow \begin{bmatrix} a & b \\ c & d \end{bmatrix} $$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.