← Back to NumPy Course | Chapter 1: Getting Started | Lesson 4 of 7

Lists की तुलना में NumPy क्यों

एक Python list कुछ भी hold कर सकती है लेकिन maths में slow है; एक NumPy array एक तरह का number hold करता है और एक साथ सब कुछ पर maths करता है।

Lists से ज़्यादा NumPy क्यों

Python lists पूरे Python objects के pointers store करती हैं, इसलिए arithmetic को एक slow loop चाहिए। NumPy arrays memory के एक contiguous block में raw numbers store करते हैं और compiled code में operations apply करते हैं। इसका मतलब है कम memory, तेज़ maths, और कहीं छोटा code।

Note: एक list को 2 से multiply करना इसे repeat करता है; एक array को 2 से multiply करना हर element double करता है।

उदाहरण: Why NumPy over lists

python
import numpy as np

nums = [1, 2, 3]
arr = np.array(nums)

print("list * 2  :", nums * 2)
print("array * 2 :", arr * 2)
print("list + list:", nums + nums)
print("array + array:", arr + arr)

# Output:
# list * 2  : [1, 2, 3, 1, 2, 3]
# array * 2 : [2 4 6]
# list + list: [1, 2, 3, 1, 2, 3]
# array + array: [2 4 6]
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. यह उम्मीद करना कि list * 2 values double करेगा
  2. types mix करना और automatic conversion से surprised होना
  3. बड़े numeric datasets के लिए lists इस्तेमाल करना
चैप्टर सारांश
  • Arrays contiguous typed memory इस्तेमाल करते हैं
  • Operators arrays पर element-wise काम करते हैं
  • Arrays lists से कहीं कम memory इस्तेमाल करते हैं
  • Code बिना explicit loops के छोटा है
🔒

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.