Statistical and mathematical functions in NumPy
Statistical and Mathematical Functions in NumPy Definition: Statistical and mathematical functions are functions used to analyze and manipulate numerica...
Statistical and Mathematical Functions in NumPy Definition: Statistical and mathematical functions are functions used to analyze and manipulate numerica...
Statistical and Mathematical Functions in NumPy
Definition:
Statistical and mathematical functions are functions used to analyze and manipulate numerical data. NumPy provides numerous built-in functions that cater to these tasks, enabling efficient and accurate computations on arrays and dataframes.
Examples:
1. Average:
The numpy.average() function calculates the average of an array of numbers.
python
data = np.array([1, 2, 3, 4, 5])
average_value = np.average(data)
print(average_value) # Output: 3
2. Standard Deviation:
The numpy.std() function computes the standard deviation of an array of numbers.
python
data = np.array([1, 2, 3, 4, 5])
standard_deviation = np.std(data)
print(standard_deviation) # Output: 1.4142135623730951
3. Mean Absolute Error (MAE):
The numpy.mae() function calculates the MAE between two arrays of numbers.
python
data1 = np.array([1, 2, 3, 4, 5])
data2 = np.array([3, 4, 5, 6, 7])
mae = np.mae(data1, data2)
print(mae) # Output: 2.0
4. Correlation:
The numpy.corrcoef() function calculates the Pearson correlation coefficient between two arrays of numbers.
python
data1 = np.array([1, 2, 3, 4, 5])
data2 = np.array([6, 7, 8, 9, 10])
correlation_coefficient = np.corrcoef(data1, data2)[0, 1]
print(correlation_coefficient) # Output: 1
5. Probability Distribution:
The numpy.random.normal() function generates random numbers from a normal (Gaussian) distribution.
python
n = 100 # Generate 100 random numbers
random_numbers = np.random.normal(loc=0, scale=1, size=(n,))
print(random_numbers) # Output: An array of random numbers from the normal distribution