quspin.tools.misc.array_to_ints
- quspin.tools.misc.array_to_ints(state_array, dtype=None)[source]
Converts a state array with binary elements to QuSpin basis type integers.
This function takes a batched state array with 0/1 elements and converts it to an array of batched QuSpin basis type integers.
- Parameters:
- state_array: np.ndarray(np.uint8)
- batched state array to be converted
- dtype: dtype, optional
data type used for the basis integers, default to be the type expressing the
- state with smallest size
- Returns:
- basis_ints: np.ndarray(int)
- batched basis integers
Notes
Conversion of higher spins or larger occupation numbers is not yet implemented.
Examples
1from quspin.basis import spin_basis_general 2from quspin.tools.misc import ints_to_array, array_to_ints 3 4N = 10 5basis = spin_basis_general(N, make_basis=False) 6 7# initial states 8num_states = 2 9state_array = np.random.randint(0, 2, (num_states, N), dtype=np.uint8) 10print(f"The {num_states} initial states are") 11print(state_array) 12 13# convert state array to basis integers 14basis_ints = array_to_ints(state_array, basis.dtype) 15 16# apply Sx on site 4 17ME, bra, ket = basis.Op_bra_ket("x", [4], 1.0, np.float64, basis_ints) 18 19# convert outcome back to state array 20bra_array = ints_to_array(bra, N) 21 22print("Applying Sx on site 4, the new states are") 23print(bra_array)