 NCL Home > Documentation > Functions > General applied math, Statistics

# zscore

Computes the zscore of a variable's given dimensions at all other dimensions and retains metadata. Available in version 6.5.0 and later.

## Prototype

```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"  ; This library is automatically loaded
; from NCL V6.2.0 onward.
; No need for user to explicitly load.

function zscore (
x        : numeric,
flag  : integer,
dims [*] : integer
)

return_val  :  float or double
```

## Arguments

x

A variable of numeric type and any dimensionality.

flag

A flag to indicate the sample or population standard deviation.

• flag=0: use the sample standard deviation: use [N-1] where N is the sample size
• flag=1: use the population standard deviation: use N, the full sample size

dims

The dimension(s) of x on which to calculate the Z-score.. Must be consecutive and monotonically increasing.

## Description

Assuming a normal distribution, a Z-score (aka, standard score) is the number of population standard deviations from the population mean a data point is. But more technically, it's a measure of how many population standard deviations below or above the populatio n mean a raw score is. In practice, the sample mean and sample standard deviation are substituted for the population values.

## Examples

Example 1: The following example matches the results at: scipy.stats.zscore

```
x  = (/0.7972,  0.0767,  0.4383,  0.7866,  0.8091, \
0.1954,  0.6307,  0.6599,  0.1065,  0.0508  /)

z0 = zscore(x, 0, 0)
z1 = zscore(x, 1, 0)

print(z0)
print(z1)
print(sprintf("%6.4f" ,z0)+"  "+sprintf("%6.4f" ,z1))
```
The (slightly) edited output is:
```
Variable: z0
Type: float
Total Size: 40 bytes
10 values
Number of Dimensions: 1
Dimensions and sizes:   
Coordinates:
Number Of Attributes: 3
long_name :   Z-Score
method :      Z=(x-xmean)/xstd ; sample std
NCL : zscore

Variable: z1
Type: float
Total Size: 40 bytes
10 values
Number of Dimensions: 1
Dimensions and sizes:   
Coordinates:
Number Of Attributes: 4
long_name :   Z-Score
method :      Z=(x-xmean)/xstd ; population std
NCL : zscore

---
z0       z1
(0)      1.0694   1.1272
(1)     -1.1830  -1.2470
(2)     -0.0526  -0.0554
(3)      1.0363   1.0923
(4)      1.1066   1.1665
(5)     -0.8119  -0.8558
(6)      0.5489   0.5786
(7)      0.6402   0.6748
(8)     -1.0898  -1.1488
(9)     -1.2640  -1.3323
```