Numpy in Python
Numpy in Python
import numpy as np
[ 4, 2, 5]] )
# Printing size (total number of elements) of array
Output :
Array is of type:
No. of dimensions: 2
Shape of array: (2, 3)
Size of array: 6
Array stores elements of type: int64
Statistics:
mean() function
The mean() function is used to calculate the arithmetic mean of the numbers in the
list.
Example
import statistics
# list of positive integer numbers
datasets = [5, 2, 7, 4, 2, 6, 8]
x = statistics.mean(datasets)
# Printing the mean
print("Mean is :", x)
Output:
Mean is : 4.857142857142857
median() function
The median() function is used to return the middle value of the numeric data in the
list.
Example
import statistics
datasets = [4, -5, 6, 6, 9, 4, 5, -2]
# Printing median of the
# random data-set
print("Median of data-set is : % s "
% (statistics.median(datasets)))
Output:
mode() function
The mode() function returns the most common data that occurs in the list.
Example
import statistics
# declaring a simple data-set consisting of real valued positive integers.
dataset =[2, 4, 7, 7, 2, 2, 3, 6, 6, 8]
# Printing out the mode of given data-set
print("Calculated Mode % s" % (statistics.mode(dataset)))
Output:
Calculated Mode 2
stdev() function
The stdev() function is used to calculate the standard deviation on a given sample
which is available in the form of the list.
Example
1. import statistics
2. # creating a simple data - set
3. sample = [7, 8, 9, 10, 11]
4. # Prints standard deviation
5. print("Standard Deviation of sample is % s "
6. % (statistics.stdev(sample)))
Output:
median_low()
The median_low function is used to return the low median of numeric data in the list.
Example
1. import statistics
2. # simple list of a set of integers
3. set1 = [4, 6, 2, 5, 7, 7]
4. # Note: low median will always be a member of the data-set.
5. # Print low median of the data-set
6. print("Low median of data-set is % s "
7. % (statistics.median_low(set1)))
Output:
median_high()
The median_high function is used to return the high median of numeric data in the
list.
Example
1. import statistics
2. # list of set of the integers
3. dataset = [2, 1, 7, 6, 1, 9]
4. print("High median of data-set is %s "
5. % (statistics.median_high(dataset)))
Output:
Math Methods
Method Description
Math Constants
Constant Description