reshape

compas.itertools.reshape(lst, shape)[source]

Gives a new shape to an array without changing its data.

This function mimics the functionality of numpy.reshape [1], but in a simpler form.

Parameters:
lstlist

A list of items.

shapeint or tuple of ints

The new shape of the list

References

Examples

>>> a = [1, 2, 3, 4, 5, 6]
>>> reshape(a, (2, 3))
[[1, 2, 3], [4, 5, 6]]
>>> reshape(a, (3, 2))
[[1, 2], [3, 4], [5, 6]]
>>> a = [[1, 2], [3, 4], [5, 6]]
>>> reshape(a, (2, 3))
[[1, 2, 3], [4, 5, 6]]