NCL Website header
NCL Home > Documentation > Functions > Array query

count_unique_values_n

Counts the number of unique values in the given array, across the given dimension.

Available in version 6.4.0 and later.

Prototype

	function count_unique_values_n (
		x       ,           
		dim [1] : integer   
	)

	return_val  :  integer or long

Arguments

x

An array of any type or dimensionality.

dim

A scalar integer indicating which dimension of x to count the unique values across.

Return value

The return value will be of type integer or long, representing the number(s) of unique values. It will be a scalar if x is a 1D array, or the same dimensions as x minus the dim dimension if x is a multi-dimensional array.

Description

This function returns a count of all the unique values in the given array across the given dimension dim. Missing values are not included in the count. If the array contains all missing values, then 0 is returned. This function will work on strings or numeric values.

Use count_unique_values if you simply want to count the total number of unique values in the whole array.

See Also

count_unique_values, get_unique_values, get_unique_difference, get_unique_intersection, get_unique_union, where, num, ind, ind_resolve

Examples

Example 1

Count the unique values of different dimensions of a multi-dimensional integer array.

  x  = (/ (/1,2,3,4,5/), (/2,2,3,3,4/), (/5,5,5,5,1/)/)
  c1 = count_unique_values_n(x,0)         ; 3,2,2,3,3
  c2 = count_unique_values_n(x,1)         ; 5,3,2