grid_outer

tenpy.linalg.np_conserved.grid_outer(grid, grid_legs, qtotal=None)[source]

Given an np.array of npc.Arrays, return the corresponding higher-dimensional Array.

Parameters
gridarray_like of {Array | None}

The grid gives the first part of the axes of the resulting array. Entries have to have all the same shape and charge-data, giving the remaining axes. None entries in the grid are interpreted as zeros.

grid_legslist of LegCharge

One LegCharge for each dimension of the grid along the grid.

qtotalcharge

The total charge of the Array. By default (None), derive it out from a non-trivial entry of the grid.

Returns
resArray

An Array with shape grid.shape + nontrivial_grid_entry.shape. Constructed such that res[idx] == grid[idx] for any index idx of the grid the grid entry is not trivial (None).

See also

detect_grid_outer_legcharge

can calculate one missing LegCharge of the grid.

Examples

A typical use-case for this function is the generation of an MPO. Say you have npc.Arrays Splus, Sminus, Sz, each with legs [phys.conj(), phys]. Further, you have to define appropriate LegCharges l_left and l_right. Then one ‘matrix’ of the MPO for a nearest neighbour Heisenberg Hamiltonian could look like:

>>> Id = np.eye_like(Sz)
>>> W_mpo = grid_outer([[Id, Splus, Sminus, Sz, None],
...                     [None, None, None, None, J*Sminus],
...                     [None, None, None, None, J*Splus],
...                     [None, None, None, None, J*Sz],
...                     [None, None, None, None, Id]],
...                    leg_charges=[l_left, l_right])
>>> W_mpo.shape
(5, 5, 2, 2)