Extract subset of an array excluding a certain element

Dear all,

I have a simple question. Given an array [1,2,3], I want to extract the subset which excludes one of the elements. I’m sure that there is a much nicer compact form than what I’m writing below. Any suggestions?

Thank you!

   implicit none
   integer :: idir, idir_n(2)
   do idir=1,3
     select case(idir)
     case(1)
       idir_n(:) = [2,3]
     case(2)
       idir_n(:) = [1,3]
     case(3)
       idir_n(:) = [1,2]
     end select
   end do
 end
1 Like

@pcosta, in addition to the ton of replies here and elsewhere, you may also want to look into the standard facilities on array elements and sections including the vector-subscript notation and the latest offering starting Fortran 202X with @ and integer expression toward multiple-subscript, for these might get you thinking beyond what you indicate in the original post here.

1 Like