C Library Functions  - transpose (3)

NAME

TRANSPOSE(3) - [ARRAY:MANIPULATION] Transpose an array of rank two

SYNOPSIS

result = transpose(matrix)

         function transpose(matrix)

type(TYPE(kind=KIND)) :: transpose(N,M) type(TYPE(kind=KIND)),intent(in) :: matrix(M,N)

CHARACTERISTICS

o MATRIX is an array of any type with a rank of two.
o The result will be the same type and kind as MATRIX and the reversed shape of the input array

DESCRIPTION

TRANSPOSE(3) transposes an array of rank two.

An array is transposed by interchanging the rows and columns of the given matrix. That is, element (i,j) of the result has the value of element (j,i) of the input for all (i,j).

OPTIONS

o MATRIX : The array to transpose

RESULT

The transpose of the input array. The result has the same type as MATRIX, and has shape [ m, n ] if MATRIX has shape [ n, m ].

EXAMPLES

Sample program:

    program demo_transpose
    implicit none
    integer,allocatable :: array(:,:)
    integer,parameter   :: values(3,5)= reshape([&
        1,  2,  3,  4,  5,    &
       10, 20, 30, 40, 50,    &
       11, 22, 33, 44, -1055  &
     ],shape(values),order=[2,1])

array=values call print_matrix_int(’array:’,array) array=transpose(array) call print_matrix_int(’array transposed:’,array) array=transpose(array) call print_matrix_int(’transposed transpose:’,array)

contains

subroutine print_matrix_int(title,arr) ! print small 2d integer arrays in row-column format implicit none character(len=*),intent(in) :: title integer,intent(in) :: arr(:,:) integer :: i character(len=:),allocatable :: biggest write(*,’(a," shape(",i0,",",i0,")")’)trim(title),shape(arr) ! print title biggest=’ ’ ! make buffer to write integer into ! find how many characters to use for integers write(biggest,’(i0)’)ceiling(log10(max(1.0,real(maxval(abs(arr))))))+2 ! use this format to write a row biggest=’(" [",*(i’//trim(biggest)//’:,","))’ ! print one row of array at a time do i=1,size(arr,dim=1) write(*,fmt=biggest,advance=’no’)arr(i,:) write(*,’(" ]")’) enddo end subroutine print_matrix_int

end program demo_transpose

Results:

     > array: shape(3,5)
     >    [     1,     2,     3,     4,     5 ]
     >    [    10,    20,    30,    40,    50 ]
     >    [    11,    22,    33,    44, -1055 ]
     > array transposed: shape(5,3)
     >    [     1,    10,    11 ]
     >    [     2,    20,    22 ]
     >    [     3,    30,    33 ]
     >    [     4,    40,    44 ]
     >    [     5,    50, -1055 ]
     > transposed transpose: shape(3,5)
     >    [     1,     2,     3,     4,     5 ]
     >    [    10,    20,    30,    40,    50 ]
     >    [    11,    22,    33,    44, -1055 ]

STANDARD

Fortran 95

SEE ALSO

o MERGE(3) - Merge variables
o PACK(3) - Pack an array into an array of rank one
o SPREAD(3) - Add a dimension and replicate data
o UNPACK(3) - Scatter the elements of a vector
Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 transpose (3) February 23, 2025
Generated by manServer 1.08 from 03f5e52f-de0e-495b-89db-0fb756cfb6f1 using man macros.