larray.Array.expand

Array.expand(target_axes=None, out=None, readonly=False) Array[source]

Expand this array to target_axes.

Target axes will be added to this array if not present. In most cases this function is not needed because LArray can do operations with arrays having different (compatible) axes.

Parameters
target_axesstring, list of Axis or AxisCollection, optional

This array can contain axes not present in target_axes. The result axes will be: [self.axes not in target_axes] + target_axes

outArray, optional

Output array, must have more axes than array. Defaults to a new array. arr.expand(out=out) is equivalent to out[:] = arr

readonlybool, optional

Whether returning a readonly view is acceptable or not (this is much faster) Defaults to False.

Returns
Array

Original array if possible (and out is None).

Examples

>>> a = Axis('a=a1,a2')
>>> b = Axis('b=b1,b2')
>>> arr = ndtest([a, b])
>>> arr
a\b  b1  b2
 a1   0   1
 a2   2   3

Adding one or several axes will append the new axes at the end

>>> c = Axis('c=c1,c2')
>>> arr.expand(c)
 a  b\c  c1  c2
a1   b1   0   0
a1   b2   1   1
a2   b1   2   2
a2   b2   3   3

If you want the new axes to be inserted in a particular order, you have to give that order

>>> arr.expand([a, c, b])
 a  c\b  b1  b2
a1   c1   0   1
a1   c2   0   1
a2   c1   2   3
a2   c2   2   3

But it is enough to list only the added axes and the axes after them:

>>> arr.expand([c, b])
 a  c\b  b1  b2
a1   c1   0   1
a1   c2   0   1
a2   c1   2   3
a2   c2   2   3