Fortran Wiki


Reshapes source to correspond to shape. If necessary, the new array may be padded with elements from pad or permuted as defined by order.


Fortran 95 and later


Transformational function


result = reshape(source, shape[, pad, order])


  • source - Shall be an array of any type.
  • shape - Shall be of type integer and an array of rank one. Its values must be positive or zero.
  • pad - (Optional) shall be an array of the same type as source.
  • order - (Optional) shall be of type integer and an array of the same shape as shape. Its values shall be a permutation of the numbers from 1 to n, where n is the size of shape. If order is absent, the natural ordering shall be assumed.

Return value

The result is an array of shape shape with the same type as source.


program test_reshape
  integer, dimension(4) :: x
  write(*,*) shape(x)                       ! prints "4"
  write(*,*) shape(reshape(x, (/2, 2/)))    ! prints "2 2"
end program

See also


category: intrinsics