NumPy shifts numerical computation away from slow Python interpreter loops into lightning-fast, C-compiled vector operations. Below is the complete reference index for mathematical transformations, universal functions (ufuncs), broadcasting alignment, multi-axis statistical aggregations, and conditional logic.
Element-wise rounding, boundary scaling, and degree-to-radian conversion utilities.
Explore vectorized arithmetic mechanics and dimension alignment rules.
Compute metrics across full arrays or target specific dimensions using axis controls.
Filter elements conditionally and test skills with practical problem sets.
import numpy as np
arr = np.array([1.0, np.nan, np.inf, -np.inf, 4.0])
print("Original:", arr)
print("isfinite:", np.isfinite(arr))
print("nanmean (ignores nan):", np.nanmean(arr))
print("clip finite values between 0 and 10:", np.clip(arr, 0, 10))
np.isfinite to check finite elements.np.nanmean.np.clip to bound values, useful in many data processing tasks.import numpy as np
z = np.array([1 + 2j, 3 - 4j, -2 + 0.5j])
print("Real parts:", np.real(z))
print("Imag parts:", np.imag(z))
print("Angles (in radians):", np.angle(z))
print("Magnitude:", np.abs(z))
import numpy as np
import time
N = 1000000
arr = np.arange(N, dtype=np.float64)
start = time.time()
res_np = np.sqrt(arr)
print("NumPy sqrt time:", time.time() - start)
start2 = time.time()
res_loop = [x**0.5 for x in arr]
print("Python loop sqrt time:", time.time() - start2)
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.