Fortran操作函數

處理函數平移功能。移位函數返回一個數組不變的形狀,但移動元素。

函數

描述

cshift(array, shift, dim)

它執行循環移位由移位置的左邊,如果移位是正和到右側,如果它是負的。如果陣列是一個矢量移位正在做以自然的方式中,如果它是一個較高級的陣列則移是沿着維數dim的所有部分。若dim缺少它被認爲是1,在其它情況下它必須是1和n(其中n等於陣列的等級)之間的標量整數。該參數換檔是一個標量整數或秩n-1個整數的數組和形狀相同的陣列中,除沿維數dim(在較低級的,因爲它被移除)。不同的部分,因此可以轉移在各個方向上,並與各種數目的位置。

eoshift(array, shift, boundary, dim)

這是端關閉的轉變。它執行向左移動,如果移位是正和到右側,如果它是負的。相反的元素移出新元素均取自邊界。如果陣列是一個矢量移位正在做以自然的方式中,如果它是一個較高級的陣列,在所有各節中的移位是以及該維度暗淡。若 dim 丟失,它被認爲是1,但在其它情況下,它爲1和n(其中n等於陣列的秩)之間有一個標量的整數值。該參數換檔是一個標量整數,如果陣列具有秩1,在其他情況下,它可以是一個標量整數或秩n-1和形狀相同的陣列排列的與除沿維數dim 的整數數組(其被取出因爲較低級的)。

transpose (matrix)

其轉置矩陣,這是秩2的陣列它取代了的行和列矩陣。

示例

下面的例子演示了這一概念:

program arrayShift implicit none

real, dimension(1:6) :: a = (/ 21.0, 22.0, 23.0, 24.0, 25.0, 26.0 /) real, dimension(1:6) :: x, y
write(*,10) a

x = cshift ( a, shift = 2) write(*,10) x

y = cshift (a, shift = -2) write(*,10) y

x = eoshift ( a, shift = 2) write(*,10) x

y = eoshift ( a, shift = -2) write(*,10) y 10 format(1x,6f6.1) end program arrayShift

當上述代碼被編譯和執行時,它產生了以下結果:

21.0 22.0 23.0 24.0 25.0 26.0
23.0 24.0 25.0 26.0 21.0 22.0
25.0 26.0 21.0 22.0 23.0 24.0
23.0 24.0 25.0 26.0 0.0 0.0
0.0 0.0 21.0 22.0 23.0 24.0

示例

下面的例子演示了轉置矩陣:

program matrixTranspose implicit none interface subroutine write_matrix(a) integer, dimension(:,:) :: a end subroutine write_matrix end interface integer, dimension(3,3) :: a, b
integer :: i, j do i = 1, 3 do j = 1, 3 a(i, j) = i end do end do print *, 'Matrix Transpose: A Matrix' call write_matrix(a) b = transpose(a) print *, 'Transposed Matrix:' call write_matrix(b) end program matrixTranspose

subroutine write_matrix(a) integer, dimension(:,:) :: a
write(*,*) do i = lbound(a,1), ubound(a,1) write(*,*) (a(i,j), j = lbound(a,2), ubound(a,2)) end do end subroutine write_matrix

當上述代碼被編譯和執行時,它產生了以下結果:

Matrix Transpose: A Matrix

1 1 1
2 2 2
3 3 3
Transposed Matrix:

1 2 3
1 2 3
1 2 3