NAME

reshape - change the shape of an array

SYNOPSIS

arr.reshape(shape)

DESCRIPTION

The reshape() method returns a new array with the same data as arr but with a new shape.

shape must be an array or list of integers specifying the new dimensions. The total number of elements in the new shape (the product of all dimensions) may be different than the total number of elements in the original arr. If the total is fewer, then the data from arr is truncated. If the total is greater, then the data from arr is repeated, starting from the first element of arr.

If arr is a scalar, it is treated as an array with a single element.

RETURN VALUE

A new array with the specified shape, containing the same data as arr.

ERRORS

TypeCheck if shape is not an array of integers

EXAMPLE

    a = [1:4]
    a.reshape([2, 2])
1 2
3 4

    a.reshape([3, 2])
1 2
3 4
1 2

SEE ALSO

shape
flatten