Session.transpose(self, *args)[source]

Reorder axes of arrays in session, ignoring missing axes for each array.


Accepts either a tuple of axes specs or axes specs as *args. Omitted axes keep their order. Use … to avoid specifying intermediate axes. Axes missing in an array are ignored.


Session with each array with reordered axes where appropriate.

See also



Let us create a test session and a small helper function to display sessions as a short summary.

>>> arr1 = ndtest((2, 2, 2))
>>> arr2 = ndtest((2, 2))
>>> sess = Session([('arr1', arr1), ('arr2', arr2)])
>>> def print_summary(s):
...     print(s.summary({LArray: "{key} -> {axes_names}"}))
>>> print_summary(sess)
arr1 -> a, b, c
arr2 -> a, b

Put ‘b’ axis in front of all arrays

>>> print_summary(sess.transpose('b'))
arr1 -> b, a, c
arr2 -> b, a

Axes missing on an array are ignored (‘c’ for arr2 in this case)

>>> print_summary(sess.transpose('c', 'b'))
arr1 -> c, b, a
arr2 -> b, a

Use … to move axes to the end

>>> print_summary(sess.transpose(..., 'a'))   # doctest: +SKIP
arr1 -> b, c, a
arr2 -> b, a