Python NumPy परिचय
In this page:
import numpy as np
array = np.array([item1, item2, item3])
NumPy क्या है?
NumPy Python में numerical computing के लिए foundational library है, जो ndarray type देती है -- एक fixed-type, multi-dimensional array जो numeric काम के लिए nested Python lists से काफी तेज़ और memory-efficient है, क्योंकि इसके elements अलग-अलग Python objects की बजाय memory में लगातार (contiguously) store होते हैं।
उदाहरण: What is NumPy?
import numpy as np
arr = np.array([1, 2, 3]) # fixed-type, contiguous ndarray
print(type(arr))
NumPy Array के Attributes
हर NumPy array के साथ built-in metadata आता है: .shape इसके dimensions एक tuple के रूप में देता है, .ndim dimensions की संख्या देता है, और .size total element count देता है।
इन attributes को पढ़ना यह जल्दी confirm करने का तरीका है कि किसी calculation को चलाने से पहले array की structure उसकी अपेक्षा से मेल खाती है।
उदाहरण: NumPy Array Attributes
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print(arr.shape, arr.ndim, arr.size) # dimensions, number of dimensions, total elements
Basic Mathematical Operations
NumPy पूरे array पर arithmetic को एक single vectorized operation में element-by-element apply करता है (a + b हर मेल खाते जोड़े के elements को एक साथ जोड़ देता है), जो अंदर से compiled C code में implement है।
यही कारण है कि बड़े arrays पर NumPy math किसी equivalent Python for loop से कई गुना तेज़ चलता है।
उदाहरण: Basic Mathematical Operations
import numpy as np
a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print(a + b) # element-wise addition, vectorized in one call
Array के Data Types
Python की list के विपरीत, जो आज़ादी से types मिला सकती है, हर NumPy array का एक fixed dtype (जैसे int32 या float64) होता है जो उसके सभी elements साझा करते हैं, जो या तो अपने-आप चुना जाता है या dtype argument से explicit रूप से।
Precision इजाज़त दे तो एक छोटा dtype चुनना array के memory footprint को काफी कम कर सकता है।
उदाहरण: Array Data Types
import numpy as np
arr = np.array([1, 2, 3], dtype="float64") # explicit fixed dtype for every element
print(arr.dtype)
Summary Statistics
NumPy arrays के साथ built-in aggregate methods आते हैं -- .sum(), .mean(), .max(), .min(), और अन्य -- जो पूरे array पर (या multi-dimensional data के लिए किसी चुने axis पर) Python में manually loop चलाकर running total जोड़ने से कहीं तेज़ गणना करते हैं।
उदाहरण: Summary Statistics
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr.sum(), arr.mean(), arr.max()) # built-in aggregate methods
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first:
- Python NumPy Introduction
- Python NumPy Arrays
- Python Pandas Introduction
- Python Pandas DataFrame
- Python Matplotlib Basics
- Python Data Visualization
- Python Statistics Module
- Python CSV & Data Analysis
- Python requests Module
- Python JSON & APIs
- Python Web Scraping Basics
- Python Flask Introduction
- Python Django Introduction
- Python MongoDB