The formula in the function is not giving the correct value - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: The formula in the function is not giving the correct value (/thread-36779.html) |
The formula in the function is not giving the correct value - quest - Mar-29-2022 Here is my function def coefficients(_list,q_number): paulis = list(product([i,x,y,z],repeat=q_number)) spaulis = list(product(['i','x','y','z'],repeat=q_number)) #print(spaulis) result = [] for k_index,kraus in enumerate(_list,start=0): print(kraus) for index, pauli in enumerate(paulis, start=0): a = 1/2*(np.trace(np.matmul(kraus,pauli))) result.append((a,spaulis[index],k_index)) return result i = np.array([[1, 0], [0, 1]]) x = np.array([[0, 1], [1, 0]]) y = np.array([[0,-1j],[1j,0]]) z = np.array([[1, 0], [0,-1]])Here is my example list: krausf=np.array([[[-9.84447177e-01-7.67061139e-18j, 1.00575460e-03+1.82351449e-02j], [-1.08968355e-03+6.25615662e-03j, -9.78901978e-01-9.19498996e-03j]]]The formula is a = 1/2*(np.trace(np.matmul(kraus,pauli))), let'stake pauli=i I should find these result for i: (-0.9816745775-0.004597494980000004j) However, I am finding: [-0.49222359-3.83530569e-18j, 0.00050288+9.11757245e-03j] from function. I can't see the point that I missed What is happening? RE: The formula in the function is not giving the correct value - quest - Mar-30-2022 This line a = 1/2*(np.trace(np.matmul(kraus,pauli))) should be a = 1/2*(np.trace(np.matmul(kraus,pauli[0]))) |