<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">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>