NumPy Introduction

NumPy Introduction
NumPy stands for Numerical Python. It is one of the most important and fundamental libraries in Python, especially used for numerical computing and scientific calculations. Many popular Python libraries like Pandas, Matplotlib, SciPy, Scikit-learn, and TensorFlow are built on top of NumPy.
If you want to work with data science, machine learning, AI, statistics, or engineering, learning NumPy is essential.
Why NumPy Was Created?
Python’s built-in data structures like lists are flexible but:
They are slow for large numerical data
They consume more memory
Mathematical operations require loops
NumPy solves these problems by providing:
Fast execution (written in C internally)
Efficient memory usage
Vectorized operations (no loops required)
What Is NumPy?
NumPy is a Python library that provides:
A powerful N-dimensional array object (
ndarray)Mathematical functions
Linear algebra operations
Random number generation
Tools for working with matrices and vectors
Core Data Structure: ndarray
The heart of NumPy is the ndarray (N-Dimensional Array).
Key Characteristics:
Stores elements of same data type
Fixed size (cannot grow like lists)
Faster than Python lists
Supports multi-dimensional data (1D, 2D, 3D…)
Example:
Output:
Dimensions in NumPy Arrays
1D Array (Vector)
2D Array (Matrix)
3D Array (Tensor)
Python List vs NumPy Array
| Feature | Python List | NumPy Array |
|---|---|---|
| Speed | Slower | Faster |
| Memory | High | Low |
| Data Type | Mixed | Same |
| Vector Operations | No | Yes |
| Scientific Use | Limited | Powerful |
Example:
Output:
Vectorization (Major Advantage)
NumPy allows vectorized operations, meaning calculations happen element-wise without loops.
Output:
This makes code:
Shorter
Faster
Easier to read
NumPy Mathematical Capabilities
NumPy supports:
Arithmetic operations (
+ - * /)Trigonometric functions (
sin,cos,tan)Statistical functions (
mean,median,std)Linear algebra (
dot,transpose,inverse)Random numbers
Example:
Broadcasting in NumPy
Broadcasting allows NumPy to perform operations on arrays of different shapes.
Output:
NumPy Installation
Install NumPy using pip:
Check version:
Where Is NumPy Used?
NumPy is widely used in:
Data Science
Machine Learning & AI
Financial Analysis
Scientific Research
Image Processing
Signal Processing
Summary
NumPy is a fast, efficient numerical library
Its core object is ndarray
Supports multi-dimensional arrays
Enables vectorized operations
Backbone of Python’s data ecosystem
