MLearning
/
Numpy
- 1 Supervised ML 4
-
Classifier S
-
Linear model S
-
Basis expansion S
-
Regularization S
- 2 Matplotlib 2
-
Subplots S
-
Pyplot S
- 3 Datasets 4
-
Iris species S
-
Diabetes S
-
Breast cancer S
-
Simulated data S
- 4 Numpy 7
-
Matrices S
-
Sparse matrices S
-
Vectorize S
-
Average S
-
Standard deviation S
-
Reshape S
-
Multiplication S
- 5 Pandas 5
-
Read data S
-
Data cleaning S
-
Find values S
-
Group rows S
-
Merge data S
- 6 Calculus 2
-
Derivatives S
-
Integrals S
- 7 Algorithms 3
-
K nearest neighbors S
-
Linear regression S
-
Gradient descent S
S
R
Q
ML Numpy Average
We can apply operation along the axes (rows or columns) np.max(matrix, axis=1) # each row np.mean(matrix, axis=0) # each column
Average
p06 We can apply operation along the axes.
""" Min, Max, Mean
We can apply operation along the axes (rows or columns).
"""
import numpy as np
matrix = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
])
print(np.max(matrix)) # 9
print(np.min(matrix)) # 1
print(np.mean(matrix)) # 5.0
assert np.max(matrix) == 9 # passed
assert np.min(matrix) == 1 # passed
assert np.mean(matrix) == 5 # passed
print(np.max(matrix, axis=1)) # [3 6 9] # max in each row
print(np.min(matrix, axis=1)) # [1 4 7] # min in each row
print(np.mean(matrix, axis=0)) # [4 5 6] # average in each column
print()
np.max(matrix, axis=1) == [3, 6, 9] # passed
np.min(matrix, axis=1) == [1, 4, 7] # passed
np.mean(matrix, axis=1) == [4, 5, 6] # passed
➥ Questions
Last update: 47 days ago