ceil | ceil value of the input elements |
floor | floor value of the input elements |
radians | Convert angels degree to radians |
rad2deg | Convert radians to degree |
round | Rounding off to nearest decimal point |
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.