NumPy Introduction
Numpy Introduction – NumPy Stands for Numerical Python, a Python library to process numerical data using Python. Numpy is also in the building block for Python Pandas– A Python Library for Data Science.
How to Install NumPy
Issue the following command on your terminal window to install NumPy.
rakesh@DESKTOP-1PBLCJ5 MINGW64 /c/python (master) $ pip install numpy Collecting numpy Downloading numpy-1.19.4-cp37-cp37m-win_amd64.whl (12.9 MB) |████████████████████████████████| 12.9 MB 2.2 MB/s Installing collected packages: numpy Successfully installed numpy-1.19.4
Note: Make very sure that you are connected to the internet.
How to use Numpy
In order to use NumPy on your machine, import NumPy as a module.
import numpy as np
first NumPy Program
Type or copy-paste the following program on your editor
import numpy as np ar = np.array([1,2,34,5]) print(ar)
When you run the above code, It generates a list of numbers using Numpy. The output is –
[1,2,34,5]
In this tutorial series, we will cover the basics of the NumPy library.
Prerequisite for NumPy
We are assuming that you are comfortable with Python Programming Language and you have sufficient knowledge to understand Python loops, lists, tuple, and dictionary. Besides that, you also know how to use the Editor.
If you are not aware of any of these topics, we would suggest your check out Python Tutorial series first and also check some assignment on Python as well as MCQ
NumPy Introduction
NumPy is the fundamental package for scientific computing in Python. It is a Python library that provides a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms basic linear algebra, basic statistical operations, random simulation and much more.
At the core of the NumPy package, is the ndarray object. This encapsulates n-dimensional arrays of homogeneous data types, with many operations being performed in compiled code for performance.
There are several important differences between NumPy arrays and the standard Python sequences:
- NumPy arrays have a fixed size at creation, unlike Python lists (which can grow dynamically). Changing the size of an array will create a new array and delete the original.
- The elements in a NumPy array are all required to be of the same data type, and thus will be the same size in memory. The exception: one can have arrays of (Python, including NumPy) objects, thereby allowing for arrays of different-sized elements.
- NumPy arrays facilitate advanced mathematical and other types of operations on large numbers of data. Typically, such operations are executed more efficiently and with less code than is possible using Python’s built-in sequences.
- A growing plethora of scientific and mathematical Python-based packages are using NumPy arrays; though these typically support Python-sequence input, they convert such input to NumPy arrays prior to processing, and they often output NumPy arrays. In other words, in order to efficiently use much (perhaps even most) of today’s scientific/mathematical Python-based software, just knowing how to use Python’s built-in sequence types is insufficient – one also needs to know how to use NumPy arrays.
The points about sequence size and speed are particularly important in scientific computing.