NumPy Introduction
Why Learn NumPy?
NumPy is a core Python library for numerical computing, built for handling large arrays and matrices efficiently. It is significantly faster than Python's built-in lists because it uses optimized C language style storage where actual values are stored at contiguous locations (not object reference).
Executes vectorized operations 10 to 100 times faster than standard Python loops. Uses homogeneous arrays to store large datasets more compactly than Python lists. Provides optimized functions for linear algebra, Fourier transforms and matrix manipulations. Includes robust tools for statistics, random number generation and missing data management. Expresses complex math in single-line commands, eliminating the need for manual, nested loops.
How to Install Numpy on Windows?
Type import numpy as np, according to the error message, PyCharm can automatically install Numpy.
Creating NumPy Arrays
1D array
import numpy as np
a1 = np.array([1, 2, 3])
print(a1)
Output
[1 2 3]
2D array
import numpy as np
a2 = np.array([[1, 2], [3, 4]])
print(a2)
Output
[[1 2]
[3 4]]
3D array
import numpy as np
a3 = np.array([[[1, 2], [3, 4]],
[[5, 6], [7, 8]]])
print(a3)
Output
[[[1 2]
[3 4]]
[[5 6]
[7 8]]]