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

np.power/sqrt का इस्तेमाल

power numbers को exponents तक raise करता है और sqrt square roots लेता है, एक साथ हर element के लिए।

In this page:

  1. np.power/sqrt
Syntax
python
np.power(a, n)
np.sqrt(a)

np.power/sqrt

np.power(a, n) a ** n का function form है और exponents का एक array भी accept करता है। np.sqrt square roots return करता है, और np.cbrt cube roots। Negative floats का sqrt लेना एक warning के साथ nan देता है; ज़रूरत पड़ने पर complex dtype इस्तेमाल करें।

Note: np.square(a) a ** 2 के लिए एक fast shortcut है।

उदाहरण: np.power/sqrt

python
import numpy as np

a = np.array([1, 2, 3, 4])
print(np.power(a, 3))
print(np.power(2, a))
print(np.sqrt(a).round(3))
print(np.cbrt(np.array([8, 27])))

# Output:
# [ 1  8 27 64]
# [ 2  4  8 16]
# [1.    1.414 1.732 2.   ]
# [2. 3.]
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. Negative numbers का square root लेना
  2. Negative exponents वाली Integer powers एक error raise करती हैं
  3. np.power को np.exp से confuse करना
चैप्टर सारांश
  • np.power ** operator से match करता है
  • Exponents arrays हो सकते हैं
  • Negatives का sqrt nan देता है
  • np.square और np.cbrt shortcuts हैं
🔒

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.