<div dir="ltr"><div>Assuming that you need ensemble means of the 40 randomly selected members for 1000 times, then something as following should work:</div><div><br></div><div>   nper   = 1000  ; number of times that you want to select 40 random members</div><div>        new_arr   = new((/nper,dimx(0),dimx(2),dimx(3)/),typeof(T2m),T2m@_FillValue)<br>        new_arr!0 = "randomEM"<br>        new_arr!1 = T2m!0<br>        new_arr!2 = T2m!2<br>        new_arr!3 = T2m!3<br>        new_arr&$new_arr!0$ = ispan(0,nper-1,1)<br>        new_arr&$new_arr!1$ = T2m&$T2m!0$<br>        new_arr&$new_arr!2$ = T2m&$T2m!2$<br>        new_arr&$new_arr!3$ = T2m&$T2m!3$<br>        new_arr&$new_arr!2$@units = T2m&$T2m!2$@units<br>        new_arr&$new_arr!3$@units = T2m&$T2m!3$@units<br>        new_arr@units = T2m@units</div><div>   <br></div><div>      <br></div><div>  do j= 0,nper-1<br>
                 iwo = generate_sample_indices( nens, 0 ) ; generate sample ids of size "nens"  <br>
                 new_arr(j,:,:,:) = dim_avg_n_Wrap(T2m(:,iwo(0:n-1),:,:),1)                      ; get average of the n=40 members<br>
            end do</div><div><br></div><div><br></div><div>hope that help!...</div><div>Rashed<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 18, 2022 at 2:21 AM Sri nandini via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Thank you!</p>
    <p>Would some one help me understand how to modify this if i need to
      subsample multiple times?</p>
    <p>Sri<br>
    </p>
    <div>On 17.02.22 19:10, Rashed Mahmood
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>Hi Sri,</div>
        <div>I am not fully sure what your end goal is here. However, if
          you need to randomly select 40 members only once then you do
          not need a loop for it. Also, if you want to select from 100
          members then the function "generate_sample_indices" should
          have n=100 instead of 40 that you used.<br>
        </div>
        <div><br>
        </div>
        <div>So if you are interested in randomly selecting <b>40
            members ONLY ONCE </b>then your code would be:</div>
        <div>Note that I turned OFF the loop because it is not needed
          for this example. You can use a loop if you need to randomly
          select 40 members many times.<br>
        </div>
        <div><br>
        </div>
        <div>;   do j= 0,n-1<br>
               iwo = generate_sample_indices( nens, 0 )<br>
               rcp_40= T2m(:,iwo(0:n-1),:,:) <br>
          <br>
          ;   end do</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Thu, Feb 17, 2022 at 8:28
            AM Sri nandini via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello dear ncl-users,<br>
            <br>
            I would like to know how to properly code for selecting 40
            random <br>
            ensemble from a 100 ensembles of my data.<br>
            <br>
            I wonder if someone could help me with this code? My
            original data is <br>
            [time | 240] x [ens | 100] x [lat | 180] x [lon | 360]<br>
            <br>
               f     = addfile ("<a href="http://temperature_data.nc" rel="noreferrer" target="_blank">temperature_data.nc</a>",
            "r")<br>
               T2m    = f->temp<br>
            <br>
               printVarSummary(T2m)<br>
               dimx = dimsizes(T2m)<br>
               ntim = dimx(0)          ; 240- time dimension<br>
               nens = dimx(1)          ; 100- ensemble dimension<br>
               nlat = dimx(2)            ; 180- lat<br>
               mlon = dimx(3)          ; 360- lon<br>
            <br>
               T2m@_FillValue = -9.96921e+36<br>
            <br>
               ; randomly select 40 members from 100 members without
            replacement<br>
               ; define a new variable dimensions<br>
            <br>
               n=40<br>
               rcp_40=new((/ntim,n,nlat,mlon/),typeof(rcp45_anom))<br>
               copy_VarCoords(rcp45_anom(:,0,:,:),rcp_40(:,0,:,:))    ;
            Copy metadata<br>
               printVarSummary(rcp_40) ==>Dimensions and sizes:   
            [time | 240] x <br>
            [40] x [lat | 180] x [lon | 360]<br>
            <br>
               Coordinates:<br>
                         time: [1192152..1366728]<br>
                         lat: [-89.5..89.5]<br>
                         lon: [   0.. 359]<br>
            <br>
               do j= 0,n-1<br>
               iwo = generate_sample_indices( n, 0 )<br>
               rcp_40(:,j,:,:) = T2m(:,iwo,:,:)  ====>error here
            fatal:VarVarWrite: <br>
            Number of dimensions on left hand side does not match right
            hand side<br>
            <br>
               end do<br>
               printVarSummary(rcp_40)<br>
            <br>
            Could someone help me in this code?<br>
            <br>
            Best<br>
            <br>
            Sri<br>
            <br>
            _______________________________________________<br>
            ncl-talk mailing list<br>
            <a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
            List instructions, subscriber options, unsubscribe:<br>
            <a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote>
        </div>
      </div>
    </blockquote>
    <pre cols="72">-- 
Dr. Sri Nandini-Weiss

Center for Earth System Research and Sustainability (CEN)
Cluster of Excellence 'Climate, Climatic Change, and Society' (CLICCS) 

Universität Hamburg
Institute of Oceanography 
Bundesstraße 53
20146 Hamburg
Germany</pre>
  </div>

_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote></div></div>