Page 186 - Robotics and AI class 10
P. 186
Modules and Libraries
Modules in Python are individual files that contain code, functions, or classes for code organisation and reusability.
They can be imported into other files using the import statement. whereas, Libraries in Python are collections of
precompiled code, functions, or resources that provide additional functionality to Python developers. They solve
specific problems or offer specific capabilities and can be installed and imported into Python projects.
Modules help organize and reuse code within a program, while libraries extend Python's capabilities by providing
ready-made solutions for various tasks or domains.
Let us now study in detail the use of some of these packages:
NumPy (‘Numerical Python’)
NumPy is a powerful open-source scientific package that stands for ‘Numerical Python’. It uses mathematical and
logical operations for handling large datasets through powerful data structure-n-dimensional arrays that also
speeds up data processing. NumPy is the first step in learning to become a Python data scientist in the future.
Various other libraries like Pandas, Matplotlib, and Scikit-learn are built on using some concepts of this magical
library. It can also be easily interfaced with other Python packages and provides tools for integrating with other
programming languages like C, C++ etc.
If you are using basic Python installed through https://www.python.org website then the NumPy package is not
included by default. You need to install it separately.
NumPy can be installed by typing following command:
pip install NumPy
Once it is installed, it can be readily used in any Python code by using import keyword as shown below:
Numpy can also be imported into the Jupyter Notebook by using the given statement :
>>> import numpy # this will import the complete numpy
# package
OR
>>> import numpy as npy # this will import numpy and referred
# as npy
OR
>>> from numpy import array #this will import ONLY arrays
#from whole numpy package
OR
>>> from numpy import array as ary #this will import ONLY
#arrays and referred as ary
Arrays are an ordered collection of values of the same data types that can be arranged in one or more dimensions.
They can be numbers, characters, Booleans, etc. The elements are referred to using index numbers(position) that
start with 0 . Almost all programming languages support arrays in one form or another.
An array of one dimension is called a Vector, an array having two dimensions is called a Matrix and an array with
multiple dimensions is called n-dimension array.
In NumPy we can create n-dimensional arrays and are considered as an alternative to Python lists because they
allow faster access in reading and writing items effectively and efficiently. The NumPy library has a large set of
built-in functions available in the form of modules and packages for creating, manipulating, and transforming
NumPy arrays.
184 Touchpad Robotics & Artificial Intelligence-X

