I have the following minimal example:
program main
double precision, dimension(3) :: rankone
double precision, dimension(3,1) :: ranktwo
double precision, dimension(3) :: output
rankone = 1
ranktwo = 2
output = rankone + ranktwo
print *, 'output: ', output
end program main
Is there a function like squeeze in Matlab that removes the singleton dimension from the variable ranktwo. I’m looking for something like
output = rankone + squeeze(ranktwo)
If not, is there any workaround for this setting?
Are there any differences between the various versions of Fortran regarding this problem?
Try this
then look at the documentation for
reshapeto see what is going on. You could also writewhich slices a 1D array out of
ranktwo. In my experiencereshapeusually causes an array copy so there may be a memory-use-efficiency argument for preferring the second version.No, there are no differences between Fortran versions regarding this problem, a 3×1 array is not the same shape as a 1D array of length 3.