0
0
NumPydata~5 mins

Installing and importing NumPy

Choose your learning style9 modes available
Introduction

NumPy helps us work with numbers and lists easily. We install and import it to use its tools in our programs.

When you want to do math with big lists of numbers quickly.
When you need to create or change arrays (like lists but better).
When you want to use functions that help with data science and math.
When you want to speed up calculations compared to normal Python lists.
Syntax
NumPy
pip install numpy

import numpy as np

Use pip install numpy in your command line to install NumPy.

Use import numpy as np in your Python code to start using NumPy with the short name np.

Examples
This command installs NumPy on your computer.
NumPy
pip install numpy
This imports NumPy but you have to type numpy every time.
NumPy
import numpy
This imports NumPy and lets you use np as a shortcut.
NumPy
import numpy as np
Sample Program

This program imports NumPy, creates an array of numbers, and prints it.

NumPy
import numpy as np

# Create a simple array using NumPy
arr = np.array([1, 2, 3, 4, 5])
print(arr)
OutputSuccess
Important Notes

Make sure you run pip install numpy before importing NumPy in your code.

If you use an environment like Jupyter Notebook, you can run !pip install numpy inside a cell.

Summary

NumPy must be installed once using pip install numpy.

Import NumPy in your code with import numpy as np for easy use.

NumPy helps with fast and easy number and array operations.