Basic Statistical Operations
NumPy
offers a suite of functions for executing basic statistical operations on NumPy
arrays, making it indispensable for data analysis. Key functions include:
mean()
: Computes the mean (average) of array elements;median()
: Determines the median (middle value) of array elements;std()
: Calculates the standard deviation, measuring the spread of the array elements;var()
: Assesses the variance, indicating the variability of array elements;min()
: Identifies the minimum value within an array;max()
: Locates the maximum value within an array;argmin()
: Finds the index of the minimum value in an array;argmax()
: Discovers the index of the maximum value in an array.
Tarefa
Swipe to start coding
- Create an array filled with 10 random values.
- Compute the mean of the array.
- Determine the median of the array.
- Calculate the standard deviation of the array.
- Assess the variance of the array.
Solução
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import numpy as np
# Create a NumPy array with random values
arr = np.random.rand(10)
# Calculate the mean of the array
mean = np.mean(arr)
# Calculate the median of the array
median = np.median(arr)
# Calculate the standard deviation of the array
std = np.std(arr)
# Calculate the variance of the array
var = np.var(arr)
display(arr)
print('Mean:', mean)
print('Median:', median)
print('Standard deviation:', std)
print('Variance:', var)
Mark tasks as Completed
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 4
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo