Skip to content

Instantly share code, notes, and snippets.

@jenssss
Created March 15, 2018 11:32
Show Gist options
  • Save jenssss/31fb98973b192c785ca76b5b785fd857 to your computer and use it in GitHub Desktop.
Save jenssss/31fb98973b192c785ca76b5b785fd857 to your computer and use it in GitHub Desktop.
Function for calculating the outer product of two vectors in fortran
function outer_product(A,B) result(AB)
double precision, intent(in) :: A(:),B(:)
double precision, allocatable :: AB(:,:)
integer :: nA,nB
nA=size(A)
nB=size(B)
allocate(AB(nA,nB))
AB = spread(source = A, dim = 2, ncopies = nB) * &
spread(source = B, dim = 1, ncopies = nA)
end function outer_product
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment