0% found this document useful (0 votes)
2 views

Numpy introduction

NumPy is an open-source Python library designed for mathematical, scientific, and engineering computations, particularly effective for handling multi-dimensional arrays and matrices. It is significantly faster than traditional Python lists, providing efficient operations for linear algebra, random number handling, and more. NumPy is widely used in data analysis and machine learning, often in conjunction with other libraries like Matplotlib and Scikit Learn.

Uploaded by

23b01a1253
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Numpy introduction

NumPy is an open-source Python library designed for mathematical, scientific, and engineering computations, particularly effective for handling multi-dimensional arrays and matrices. It is significantly faster than traditional Python lists, providing efficient operations for linear algebra, random number handling, and more. NumPy is widely used in data analysis and machine learning, often in conjunction with other libraries like Matplotlib and Scikit Learn.

Uploaded by

23b01a1253
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

→ What is Python NumPy Library?

Numpy is a shorthand form of "Numeric Python" or "Numerical


Python" and it is pronounced as (Num-pee).
 NumPy is an open-source library in Python that provides
support in mathematical, scientific, engineering, and data
science programming.
 Numpy is an incredible library to perform large mathematical
and statistical operations .
 Numpy is basically a simple programming language that works
superbly well for the multi-dimensional arrays and matrices
multiplication.
 In 2005, Numpy was created by Travis Oliphant and as it is open-
source so anyone can access it freely.
 Numpy is a great tool for any scientific project and it also contains
a powerful n-dimensional array object.
NumPy Library is written partially in Python and the parts of NumPy that
require fast computation are written in C or C++.

→ Where is Numpy used?


Below we have some usecases where NumPy is effective to use:
 Numpy is very useful in performing operations that are related
to linear algebra and for its handling of random numbers.
 NumPy can efficiently implement multi-dimensional array
objects (that are in the form of rows and columns).
 Numpy works efficiently with reshaping of matrices, random
numbers, and Fourier transforms, etc.
 Numpy was designed for scientific computation.
 TensorFlow and Scikit learn also uses NumPy array to compute
the matrix multiplication in their back end

→ Why to use Numpy in Python?


Because, in Python, Lists are used in order to serve the purpose of the
array but lists are very slow to process. Hence we use Numpy in Python
because it provides an array object that is up to 50x faster than traditional
Python lists. And Python has other modules too, which makes data
analysis and presentation very easy. So Numpy library is used with Python
along with other Python libraries like Matplotlib, Scikit Learn, etc for AI/ML
and Data analysis purposes.
 In NumPy, the array object is commonly known as ndarray. Numpy
provides a lot of supporting functions for performing operations
on its array object and with these functions, working
with ndarray becomes very easy.
 Also, the NumPy arrays are more compact than Python Lists in
terms of the size.
 NumPy uses much less memory in order to store data and it
provides an easy mechanism of specifying the data types.
Thus code can be optimized easily.
→ NumPy works faster than lists.
NumPy arrays are mainly stored at one continuous place in memory
contrary to lists. Thus you can access and manipulate them very
efficiently and this behavior is commonly known as locality of
reference. Due to this reason, Numpy is faster than lists. Numpy
is optimized to work with latest CPU architecture.

→ Differences between a list and NumPy array


Lists NumPy arrays
Python lists store a collection of NumPy arrays only store a single type
ordered, alterable data objects of object
Elements of the list are scattered Elements of the NumPy array are
around the memory stored in contiguous memory locations
Operations like insertion, deletion, All the operations performed on lists
concatenation, appending etc can be can also be performed on arrays. Some
performed on lists. But some of the additional operations can also be
operations performed on arrays can not performed on arrays.
be performed on lists Ex: a = [1, 3, 5] and b = [2, 4, 6]
Ex: a = [1, 3, 5] and b = [2, 4, 6] a*b returns [2, 12, 30]
a*b returns an error
Lists are significantly slower than NumPy arrays are significantly faster
NumPy arrays than lists

→ Using NumPy in our code


To add the NumPy to our application code there are two points to
remember:
 NumPy can be added using the keyword import
 Numpy is popularly imported under its np alias, so you can create an
alias using as keyword. It is not mandatory to create an alias but for
ease of use we can create its alias.
Thus the command to import Numpy is:
import numpy

Also, the command to import Numpy with its alias:


import numpy as np

→ Checking the version of Numpy in our system:


If you want to check the version of Numpy then it is important to note that the version
string is mainly stored under __version__ attribute. You can check using the following
code:
import numpy as np
print(np.__version__)

You might also like