Jul-04-2023, 12:24 AM
I have a list which contains may matrices. I called this list as su4_np and it contains more than 500 matrices
When I want to add a matrix to the list, I want to check if there is any matrix in the list which is identical to the matrix that I want to add. If there is no matrix identical to the matrix which I want to add, then add the matrix to the list:
I simply wrote the following scripts:
The output:
[[-0.500000000000000 0 -0.30902099609375 - 0.8089599609375*I 0]
[0 -0.500000000000000 0 -0.30902099609375 - 0.8089599609375*I]
[0.30902099609375 - 0.8089599609375*I 0 -0.500000000000000 0]
[0 0.30902099609375 - 0.8089599609375*I 0 -0.500000000000000]]
[[(-0.30902099609375-0.5j) 0 (-0-0.8089599609375j) 0]
[0 (-0.30902099609375-0.5j) 0 (-0-0.8089599609375j)]
[(-0-0.8089599609375j) 0 (-0.30902099609375+0.5j) 0]
[0 (-0-0.8089599609375j) 0 (-0.30902099609375+0.5j)]]
The matrices are not equal!! How to solve this issue?
Thanks in advance
When I want to add a matrix to the list, I want to check if there is any matrix in the list which is identical to the matrix that I want to add. If there is no matrix identical to the matrix which I want to add, then add the matrix to the list:
I simply wrote the following scripts:
deneme = np.array([[-0.30902099609375 - 0.5j, 0, -0.8089599609375j, 0], [0, -0.30902099609375 - 0.5j, 0, -0.8089599609375j], [-0.8089599609375j, 0, -0.30902099609375 + 0.5j, 0], [0, -0.8089599609375j, 0, -0.30902099609375 + 0.5j]],dtype=object) if any(np.array_equal(deneme, in_su4) for in_su4 in su4_np): print(mat) print(deneme)where su4_np is my list. However, the scripts prints the two matrix as if they are equal. But they are not equal:
The output:
[[-0.500000000000000 0 -0.30902099609375 - 0.8089599609375*I 0]
[0 -0.500000000000000 0 -0.30902099609375 - 0.8089599609375*I]
[0.30902099609375 - 0.8089599609375*I 0 -0.500000000000000 0]
[0 0.30902099609375 - 0.8089599609375*I 0 -0.500000000000000]]
[[(-0.30902099609375-0.5j) 0 (-0-0.8089599609375j) 0]
[0 (-0.30902099609375-0.5j) 0 (-0-0.8089599609375j)]
[(-0-0.8089599609375j) 0 (-0.30902099609375+0.5j) 0]
[0 (-0-0.8089599609375j) 0 (-0.30902099609375+0.5j)]]
The matrices are not equal!! How to solve this issue?
Thanks in advance