Javatpoint Logo
Javatpoint Logo

Numpy statistical functions

Numpy provides various statistical functions which are used to perform some statistical data analysis. In this section of the tutorial, we will discuss the statistical functions provided by the numpy.

Finding the minimum and maximum elements from the array

The numpy.amin() and numpy.amax() functions are used to find the minimum and maximum of the array elements along the specified axis respectively.

Consider the following example.

Example

Output:

The original array:

[[ 2 10 20]
 [80 43 31]
 [22 43 10]]

The minimum element among the array: 2
The maximum element among the array: 80

The minimum element among the rows of array [ 2 10 10]
The maximum element among the rows of array [80 43 31]

The minimum element among the columns of array [ 2 31 10]
The maximum element among the columns of array [20 80 43]

numpy.ptp() function

The name of the function numpy.ptp() is derived from the name peak-to-peak. It is used to return the range of values along an axis. Consider the following example.

Example

Output:

Original array:
 [[ 2 10 20]
 [80 43 31]
 [22 43 10]]

ptp value along axis 1: [18 49 33]
ptp value along axis 0: [78 33 21]

numpy.percentile() function

The syntax to use the function is given below.

It accepts the following parameters.

  1. input: It is the input array.
  2. q: It is the percentile (1-100) which is calculated of the array element.
  3. axis: It is the axis along which the percentile is to be calculated.

Consider the following example.

Example

Output:

Array:
 [[ 2 10 20]
 [80 43 31]
 [22 43 10]]

Percentile along axis 0 [ 6.  16.6 12. ]
Percentile along axis 1 [ 3.6 33.4 12.4]

Calculating median, mean, and average of array items

The numpy.median() function:

Median is defined as the value that is used to separate the higher range of data sample with a lower range of data sample. The function numpy.median() is used to calculate the median of the multi-dimensional or one-dimensional arrays.

The numpy.mean() function:

The mean can be calculated by adding all the items of the arrays dividing by the number of array elements. We can also mention the axis along which the mean can be calculated.

The numpy.average() function:

The numpy.average() function is used to find the weighted average along the axis of the multi-dimensional arrays where their weights are given in another array.

Consider the following example.

Example







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA