# grid_outer¶

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

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

Parameters
• grid (array_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_legs (list of LegCharge) – One LegCharge for each dimension of the grid along the grid.

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

• grid_labels (list of {str | None}) – One label associated to each of the grid axes. None for non-named labels.

Returns

res – 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).

Return type

Array

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, Id, 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:

>>> W_mpo = grid_outer([[Id, Splus, Sminus, Sz, None],
...                     [None, None, None, None, J*0.5*Sminus],
...                     [None, None, None, None, J*0.5*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)