Which components are different? Did you inspect the individual components within that line to ensure that they are yielding the same values in both languages? There are two matrices (and a transpose) and two constants. Also, in your Python code you aren't iterating through the KX list. You can change the line to:
I am only suggesting this as you have written a note in the Python that you are sure of all the code up until final portion. Therefore, if something has gone wrong it will be at the end.
[EDIT]: I used the Matlab name instead by mistake. Have changed KX to Kpoints
[EDIT #2]: Note, if you do this method, you do NOT need to change the H_tot line as kx will refer to the actual values within the elements. The method
BELOW references the
INDICES of elements in the array and thus requires H_tot to be changed