Introduction to NumPy is the perfect starting point for anyone exploring data science or scientific computing with Python. NumPy provides powerful tools for working with arrays and performing fast numerical operations, making it a core library in the Python ecosystem.
Topics Covered
Introduction to NumPy
Here what you learn in this article Introduction to NumPy.
- Introduction to arrays
- Difference between arrays and python lists
- What is NumPy?
- Why NumPy?
- Installation of NumPy library
- Creating Arrays Using NumPy
Introduction to Arrays
It is a fundamental linear Data Structure, A linear data structure is a way of organizing data where elements are arranged sequentially, and each element is connected to its previous and next element.
It is a collection of similar kind (homeogenious) of data items stored at contiguous locations.
It is simple and efficient in managing data collection of same type.
There are two types of arrays –
- 1 Dimensional Arrays
- 2 Dimensional Arrays
Difference between Arrays and Lists
Feature | Array | List |
Homogeneity | Same type elements | Different type elements |
Size Flexibility | Fixed-size once created | Dynamic size; can grow or shrink |
Memory Efficiency | More memory efficient | Less memory-efficient |
Built-in Methods | Fewer built-in methods | Rich set of built-in methods |
Module Requirement | Requires NumPy module | No module required |
Usage | Suitable for numerical operations and when interfacing with C libraries. | General purpose; suitable for a wide range of tasks. |
What is NumPy?
NumPy stands for Numeric Python. It is python library created by Travis Oliphant in 2005. It was mainly written in C or C++ or Python (partially).
Numpy performs fast operations on Arrays . NumPy is faster than Python lists because:
- Contiguous memory allocation: NumPy arrays store data in a single continuous block of memory, enabling faster access and processing.
- Fixed data types: Unlike lists, which can store mixed data types, NumPy arrays use a single data type, reducing overhead.
- Vectorized operations: NumPy performs element-wise operations using highly optimized C and Fortran libraries, avoiding slow Python loops.
The core object of NumPy is ndarray that offers mathematical, logical, sorting, selection, linear algebra, statical operations etc.
Why NumPy?
As we have discussed earlier Python lists are slow in processing. NumPy works more faster than lists. The core object ndarray support lots of supporting functions and it helpful in data science and data analysis. It works on locality of reference principle.
The principle of locality of reference refers to the tendency of a program to access the same set of memory locations repeatedly over a short period of time, either:
- Temporally (same location accessed repeatedly), or
- Spatially (locations near recently accessed data are accessed soon after).
This principle helps improve performance by making better use of caches and memory hierarchies.
Installation of NumPy
Before working with numpy you need to check the NumPy is installed or not. To check numpy is installed or not:
- Open run and type cmd
- Type pip list
- Check numpy is there or not in the list

Installing numpy is quite easy:
- Open run and type cmd
- Type pip install numpy
- Press enter after some processes it will be installed
Using NumPy
Use import statement after installation to work with NumPy
import numpy as np
Where “import” and “as” is a keyword and np is alias name
Now write “np.” to use NumPy
Checking version of NumPy
import numpy as np
print(np.__version__)
Creating Arrays
empty() – creates arrays whose initial content is random() and depends on the state of memory
array()– Accepts sequences as argument that can be two dimensional or three dimensional and so on.
zeros() – creates array of zero in specified shape
ones() – creates array of ones in specified shape
arange() – creates arrays from the specified range, accept float value as step
linspace() – Create array of evenly spaced numbers
tile() – create an array by repeating a smaller array a specified number of times
eye() – creates a 2-D array with ones on the diagonal and zeros elsewhere. Identity matrix
identity() – creates a square identity matrix — a 2-D array with ones on the main diagonal and zeros elsewhere.
full() – creates a new array of a specified shape and fills it with a constant value
Watch this video for practical understanding:
Download the jupyter notebook file created in live session by following this link:
If you are looking for python basic programs, follow this link:
That wraps up our Introduction to NumPy! Whether you’re just starting your journey into machine learning or brushing up on core Python tools, mastering NumPy is a step in the right direction. If you found this post helpful, don’t forget to like, share, and drop a comment below—your feedback helps me create better content for learners like you!