# [ncl-talk] Complicated nd to 1d to nd

Buzan, Jonathan jbuzan at purdue.edu
Tue May 11 01:36:34 MDT 2021

```Hi NCL-Talk,

My script is taking forever to execute because of loops.
I am attempting to remedy this situation by using ndtooned, then executing the commands, followed by rebuilding the array back to nd.

In my example below percentileStatsT is an array 4d array that is percentileStatsT(lat*lon,model,percentile,statistics), but I need to convert the lat*lon to lat, lon aka a 5d array:
nd_T_percentileStats(lat,lon,model,percentile,statistics)

However, I am not sure how to convert lat*lon into lat,lon. Is there a command in ncl that will do this?

Cheers,
-Jonathan

Code snippet:
ex.
T(time,lat,lon)  ;my data of temperatures

;;;create new array to store statistics.;;;;;
model = ispan(0,0,1) ; this will be the unlimited domain
model!0 = "model"
model&model = model
model at long_name = "model"

percentile = ispan(1,99,1)
percentile!0 = "percentile"
percentile&percentile = percentile
percentile at long_name = "percentile"

statfour = ispan(0,3,1)
statfour!0 = "statfour"
statfour&statfour = statfour
statfour at long_name = "Mean, SD, Skewness, Kurtosis"

percentileStatsT  = new((/dimsizes(lat)*dimsizes(lon),dimsizes(model),dimsizes(percentile),dimsizes(statfour)/), "double")

;;;;; manipulate data to calculate statistics;;;;;;
T_1d = ndtooned(T(lat|:,lon|:,time|:) ; reorder dimensions and convert to 1d

;;;;; operate on data;;;;;;;
;;;;; breaks;;;;;;;
do k = 0, (dimsizes(lat) * dimsizes(lon) -1)
index_time_st = dimsizes(time) * k
index_time_end = dimsizes(time) * k + (dimsizes(time) -1)
onedT = T_1d(index_time_st:index_time_end)
workT_Index = dim_pqsort_n(onedT,2,0)
manip_T = onedT(workT_Index)	; reorder data from lowest to highest
percentile = new((/99/),"integer”)
do l = 0, dimsizes(percentile) -1 ; time is 29200 data points. dividing the array into percentiles
starti = 292*l + 146
endi = 292*(l+1) + 146 -1
percentileStatsT(k,:,l,:) = dim_stat4(onedT(starti:endi))
end do
end do

```