We’re going to explore NumPy (NumPy Basic Functions I), a fundamental library for numerical analysis. I’ll guide you through the basic usage in three steps.
NumPy란?
Numerical Python (NumPy) is Python’s core library for numerical computations, developed by Travis Oliphant in 2005. It offers a wide range of mathematical and scientific functions, optimized for handling multidimensional array objects (ndarray) efficiently.
History of NumPy
- Numeric (1995) – Python’s first numerical computation library, developed by Jim Hugunin.
- Numarray (2001) – An improved version of Numeric, designed to handle larger arrays efficiently.
- NumPy (2005) – The modern NumPy, created by merging Numeric and Numarray, developed by Travis Oliphant.
이후, NumPy는 계속 발전하면서 과학, 공학, 데이터 분석 분야에서 필수 라이브러리가 되었습니다.
Let’s take a look at the most basic usage.
Numpy basic functions I Code
import numpy as np
a = np.array([1, 2, 3])
print(a) #[1 2 3]
z = np.zeros((3, 4)) # 0 init
print(z)
#[[0. 0. 0. 0.]
# [0. 0. 0. 0.]
# [0. 0. 0. 0.]]
o = np.ones((2, 3)) # 1 initå
print(o)
#[[1. 1. 1.]
# [1. 1. 1.]]
e = np.empty((2, 2)) # non-init
print(e)
#[[1.5e-323 4.0e-323]
# [4.0e-323 4.0e-323]]
ar = np.arange(10)
print(ar) # [0 1 2 3 4 5 6 7 8 9]
ar_step = np.arange(0, 10, 2)
print(ar_step) # [0 2 4 6 8]
lin = np.linspace(0, 1, 5)
print(lin) # [0. 0.25 0.5 0.75 1. ]
Output
[1 2 3]
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
[[1. 1. 1.]
[1. 1. 1.]]
[[ 2.31584178e+077 -2.00389588e+000]
[ 9.88131292e-324 2.78134232e-309]]
[0 1 2 3 4 5 6 7 8 9]
[0 2 4 6 8]
[0. 0.25 0.5 0.75 1. ]
Top Uses of NumPy
1. Scientific and Engineering Calculations
- Perform mathematical operations like linear algebra, differential equations, and Fourier transforms.
- Used alongside SciPy and Matplotlib for research and simulations.
2. Data Analytics & Machine Learning
- Works with Pandas and Scikit-learn for data preprocessing and machine learning model implementation.
- Enables fast array operations to process large datasets efficiently.
3. Computer Vision & Image Processing
- Used with OpenCV for image filtering, transformation, and analysis.
- Optimizes per-pixel operations for faster computations.
4. Financial & Economic Analysis
- Applied in financial simulations, risk analysis, and equity data processing.
- Efficiently handles large financial datasets using high-speed matrix operations.
5. Big Data & AI
- Powers deep learning libraries like TensorFlow and PyTorch with NumPy-based operations.
- Plays a key role in data transformation and optimization calculations.