2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. index:: RESHAPE, array, change dimensions, array, transmogrify
10 RESHAPE --- Function to reshape an array
11 ****************************************
13 .. function:: RESHAPE(SOURCE, SHAPE, PAD, ORDER)
15 Reshapes :samp:`{SOURCE}` to correspond to :samp:`{SHAPE}`. If necessary,
16 the new array may be padded with elements from :samp:`{PAD}` or permuted
17 as defined by :samp:`{ORDER}`.
20 Shall be an array of any type.
23 Shall be of type ``INTEGER`` and an
24 array of rank one. Its values must be positive or zero.
27 (Optional) shall be an array of the same
28 type as :samp:`{SOURCE}`.
31 (Optional) shall be of type ``INTEGER``
32 and an array of the same shape as :samp:`{SHAPE}`. Its values shall
33 be a permutation of the numbers from 1 to n, where n is the size of
34 :samp:`{SHAPE}`. If :samp:`{ORDER}` is absent, the natural ordering shall
38 The result is an array of shape :samp:`{SHAPE}` with the same type as
45 Transformational function
48 .. code-block:: fortran
50 RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])
53 .. code-block:: fortran
56 INTEGER, DIMENSION(4) :: x
57 WRITE(*,*) SHAPE(x) ! prints "4"
58 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"