← Back to NumPy Course | Chapter 6: Math Operations | Lesson 3 of 7

Universal Functions (ufuncs) क्या हैं

ufuncs NumPy के fast built-in functions हैं जो एक साथ एक array के हर element पर काम करते हैं।
Syntax
python
np.sqrt(arr)
np.exp(arr)
np.add(arr1, arr2)
np.sin(arr)

Universal Functions (ufuncs)

एक universal function एक vectorized function है जो element by element apply होता है, जैसे np.sqrt, np.exp, np.sin, np.add, और np.maximum। ये broadcasting और out और where जैसे optional arguments support करते हैं।

Binary ufuncs reduce और accumulate जैसे methods भी offer करते हैं।

Note: np.add.reduce(a) a.sum() के बराबर है, और np.add.accumulate(a) running totals देता है।

उदाहरण: Universal functions (ufuncs)

python
import numpy as np

a = np.array([1, 4, 9, 16])
print(np.sqrt(a))
print(np.exp(np.array([0, 1])))
print(np.maximum(a, 5))
print(np.add.accumulate(a))

# Output:
# [1. 2. 3. 4.]
# [1.         2.71828183]
# [ 5  5  9 16]
# [ 1  5 14 30]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. arrays पर math.sqrt इस्तेमाल करना, जो सिर्फ scalars accept करता है
  2. जहाँ एक ufunc exist करता है वहाँ एक loop लिखना
  3. यह भूल जाना कि ufuncs नए arrays return करते हैं
चैप्टर सारांश
  • ufuncs element-wise operate करते हैं
  • ये broadcasting support करते हैं
  • Arrays के लिए math.sqrt से np.sqrt prefer करें
  • reduce और accumulate aggregate करते हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.