# to_array¶

tenpy.tools.misc.to_array(a, shape=(None, ))[source]

Convert a to an numpy array and tile to matching dimension/shape.

This function provides similar functionality as numpys broadcast, but not quite the same: Only scalars are broadcasted to higher dimensions, for a non-scalar, we require the number of dimension to match. If the shape does not match, we repeat periodically, e.g. we tile (3, 4) -> (6, 16), but (4, 4) -> (6, 16) will raise an error.

Parameters
ascalar | array_like

The input to be converted to an array. A scalar is reshaped to the desired dimension.

shapetuple of {None | int}

The desired shape of the array. An entry None indicates arbitrary len >=1. For int entries, tile the array periodically to fit the len.

Returns
a_arrayndarray

A copy of a converted to a numpy ndarray of desired dimension and shape.