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

np.sum/min/max का इस्तेमाल

एक array को एक single number में collapse करें, या axis argument इस्तेमाल करके हर row या column collapse करें।

In this page:

  1. np.sum/min/max
Syntax
python
np.sum(arr)
np.min(arr, axis=0)
np.max(arr, axis=1)

np.sum/min/max

sum, min, और max default से एक array को एक value में reduce करते हैं। axis=0 के साथ ये columns के नीचे काम करते हैं, और axis=1 rows के आर-पार। argmin और argmax values की बजाय positions return करते हैं।

Note: keepdims=True reduced axis को length 1 की तरह रखता है, जो बाद में broadcasting में मदद करता है।

उदाहरण: np.sum/min/max

python
import numpy as np

m = np.array([[3, 1, 4], [1, 5, 9]])
print(m.sum(), m.min(), m.max())
print("column sums:", m.sum(axis=0))
print("row max:", m.max(axis=1))
print("argmax:", m.argmax())

# Output:
# 23 1 9
# column sums: [ 4  6 13]
# row max: [4 9]
# argmax: 5
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. axis 0 और axis 1 mix up करना
  2. एक बड़े array पर Python का sum इस्तेमाल करना, जो slow है
  3. यह भूल जाना कि argmax एक index return करता है
चैप्टर सारांश
  • Reductions default से एक value return करते हैं
  • axis=0 columns के नीचे जाता है
  • axis=1 rows के आर-पार जाता है
  • argmin और argmax indices return करते हैं
🔒

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.