Introduction :-
If you quit from the Python interpreter and enter it again, the
definitions you have made (functions and variables) are lost.
Therefore, if you want to write a somewhat longer program, you are better
off using a text editor to prepare the input for the interpreter and running it
with that file as input instead.
This is known as creating a script. As your program gets longer, you may
want to split it into several files for easier maintenance. You may also want
to use a handy function that you’ve written in several programs without
copying its definition into each program.
To support this, Python has a way to put definitions in a file and use them in
a script or in an interactive instance of the interpreter. Such a file is called
a module;
definitions from a module can be imported into other modules or into
the main module (the collection of variables that you have access to in a
script executed at the top level and in calculator mode).
Modules
What is a Module?
Consider a module to be the same as a code library.
A file containing a set of functions you want to include in your application.
Create Modules
1. writing a module means simply creating a file which can contains python
definitions .The file name is the module name with the extension .py. To include
module in a file , use import statements.
2. Create a first fiel as apython program with extension as.py . This is your
module file where we can write a function which performs some task .
3. Create a second file int the same directory called amin file where we can
import the module at the top of file and call the functions .
For.Example
Create a Module
To create a module just save the code you want in a file with the file
extension .py:
Example
Save this code in a file named mymodule.py
def greeting(name):
print("Hello, " + name)
Use a Module
Now we can use the module we just created, by using
the import statement:
Example
Import the module named mymodule, and call the greeting
function:
import mymodule
mymodule.greeting("Jonathan")
Built in Module
1. module is a collection of pyhton objects such as functions
,classes and so on .
Python interpreter is bundled with a standard libarary
consisting of alrge numbers of built in modules .
2. Built in modules are generally written in C and bundled
with python interpreter in precompiled form . A built in
Modules may be a python script with .py extension .
3. In addition to built-in functions, a large number of pre-
defined functions are also available as a part of libraries
bundled with Python distributions. These functions are
defined in modules are called built-in modules.
1. Math and cmath module
Python math Module
1.Python has a built-in module that you can use for
mathematical tasks.
2. The math module has a set of methods and constant.
3. The math module gives us access to hyperbolic ,
trignometric , and logarithmetoic functions for real
numbers and cmath module allows us to work with
mathematical functions
Arithmetic Functions
These functions perform various arithmetic operations like calculating the
floor, ceiling, or absolute value of a number using the floor(x), ceil(x), and
fabs(x) functions respectively.
The function ceil(x) will return the smallest integer that is greater than or
equal to x.
Similarly, floor(x) returns the largest integer less than or equal to x.
The fabs(x) function returns the absolute value of x.
You can also perform non-trivial operations like calculating the factorial of a
number using factorial(x).
import math
math.ceil(1.001) # returns 2
math.floor(1.001) # returns 1
math.factorial(10) # returns 3628800
math.gcd(10,125) # returns 5
math.trunc(1.001) # returns 1
math.trunc(1.999) # returns 1
Trigonometric Functions
You can calculate sin(x), cos(x), and tan(x) directly
using this module.
However, there is no direct formula to calculate
cosec(x), sec(x), and cot(x), but their value is equal to
the reciprocal of the value returned by sin(x), cos(x),
and tan(x) respectively.
import math
math.sin(math.pi/4) # returns 0.7071067811865476
math.cos(math.pi) # returns -1.0
math.tan(math.pi/6) # returns 0.5773502691896257
math.hypot(12,5) # returns 13.0
math.atan(0.5773502691896257) # returns
0.5235987755982988
math.asin(0.7071067811865476) # returns
0.7853981633974484
Hyperbolic functions are analogs of trigonometric functions that are based on
a hyperbola instead of a circle. I
n trigonometry, the points (cos b, sin b) represent the points of a unit circle. In
the case of hyperbolic functions, the points (cosh b, sinh b) represent the
points that form the right half of an equilateral hyperbola.
Just like the trigonometric functions, you can calculate the value
of sinh(x), cosh(x), and tanh(x) directly. The rest of the values can be
calculated using various relations among these three values.
There are also other functions like asinh(x), acosh(x), and atanh(x),
which can be used to calculate the inverse of the corresponding
hyperbolic values.
Hyperbolic functions
import math
math.sinh(math.pi) # returns 11.548739357257746
math.cosh(math.pi) # returns 11.591953275521519
math.cosh(math.pi) # returns 0.99627207622075
math.asinh(11.548739357257746) # returns 3.141592653589793
math.acosh(11.591953275521519) # returns 3.141592653589793
math.atanh(0.99627207622075) # returns 3.141592653589798
In Python, there is a module called Decimal, which is used to do
some decimal floating point related tasks. This module provides
correctly-rounded floating point arithmetic.
To use it at first we need to import it the Decimal standard library
module.
import decimal
2. Decimal Module
The square root function sqrt() and Exponent function exp()
The sqrt() method is used to calculate the square root of a given
decimal type object. And the exp() method returns the e^x value
for the given x as Decimal number.
Python in its definition provides certain methods to perform faster
decimal floating point arithmetic using the module “decimal”.
Important operations on Decimals
1. sqrt() :- This function computes the square root of the decimal
number.
2. exp() :- This function returns the e^x (exponent) of the decimal
number.
Example Code
#Perform sqrt() and exp() methods
import decimal
my_dec = decimal.Decimal(25.36)
print(my_dec)
#Find Square Root
print('Square Root is: ' + str(my_dec.sqrt()))
#Find e^x
print('e^x is: ' + str(my_dec.exp()))
Output
25.3599999999999994315658113919198513031005859375
Square Root is: 5.035871324805668565859161094
e^x is: 103206740212.7314661465187086
3.Fraction Module
This module provides support for rational number arithmetic.
It allows to create a Fraction instance from integers, floats,
numbers, decimals and strings.
Fraction Instances : A Fraction instance can be constructed
from a pair of integers, from another rational number, or from
a string. Fraction instances are hashable, and should be
treated as immutable.
4. Python - Statistics Module
The statistics module provides functions to mathematical
statistics of numeric data. The following popular statistical
functions are defined in this module.
5. Time Functions in Python
What is Tick?
Time intervals are floating-point numbers in units of seconds.
Particular instants in time are expressed in seconds since
00:00:00 hrs January 1, 1970(epoch).
There is a popular time module available in Python which
provides functions for working with times, and for converting
between representations. The function time.time() returns the
current system time in ticks since 00:00:00 hrs January 1,
1970(epoch).
Epoch:- a particular period of time in history or a person's life
1.. time() :- This function is used to count the number of seconds
elapsed since the epoch.
2. gmtime(sec) :- This function returns a structure with 9
values each representing a time attribute in sequence. It
converts seconds into time attributes(days, years, months
etc.) till specified seconds from epoch. If no seconds are
mentioned, time is calculated till present.
3. asctime(“time”) :- This function takes a time attributed string
produced by gmtime() and returns a 24 character string denoting
time.
4. ctime(sec) :- This function returns a 24 character time string but
takes seconds as argument and computes time till mentioned
seconds. If no argument is passed, time is calculated till present.
5. sleep(sec) :- This method is used to halt the program
execution for the time specified in the arguments.
6. Python Datetime Module
A date in Python is not a data type of its own, but we
can import a module named datetime to work with
dates as date objects.
Example
Import the datetime module and display the current
date:
Example :-
import datetime
x = datetime.datetime.now()
print(x)
Output:-
Creating Date Objects
Example :
import datetime
x = datetime.datetime.now()
print(x.year)
print(x.strftime("%A"))
Output :-
Python defines an inbuilt module “calendar” which handles
operations related to the calendar.
Operations on the calendar :
1. calendar(year, w, l, c):- This function displays the year, the
width of characters, no. of lines per week, and column
separations.
2. firstweekday() :- This function returns the first week day
number. By default 0 (Monday).
7 . Calendar
8.Python - sys Module
Python sys module
The python sys module provides functions and
variables which are used to manipulate different parts
of the Python Runtime Environment. It lets us access
system-specific parameters and functions.
import sys
1. sys.modules
This function provides the name of the existing python
modules which have been imported
Input and Output using sys
The sys modules provide variables for better control over input or output. We
can even redirect the input and output to other devices. This can be done using
three variables –
•stdin
•stdout
•Stderr
1. stdin: It can be used to get input from the command line directly. It used is
for standard input. It internally calls the input() method. It, also, automatically
adds ‘n’ after each sentence.
Example:
stdout: A built-in file object that is analogous to the interpreter’s
standard output stream in Python.
stdout is used to display output directly to the screen console.
Output can be of any form, it can be output from a print statement,
an expression statement, and even a prompt direct for input. By
default, streams are in text mode.
In fact, wherever a print function is called within the code, it is first
written to sys.stdout and then finally on to the screen.
output
stderr: Whenever an exception occurs in Python it is written to
sys.stderr.
Example:
output
9.Python Random Module
Python Random module is an in-built module of Python which is
used to generate random numbers. These are pseudo-random
numbers means these are not truly random. This module can be
used to perform random actions such as generating random
numbers, print random a value for a list or string, etc.
Example: Printing a random value from a list
The random module has a set of methods:
The randrange() method returns a randomly
selected element from the specified range.
Syntax
random.randrange(start, stop, step)
User defined function
In Python, a user-defined function's declaration begins with
the keyword def and followed by the function name.
The function may take arguments(s) as input within the
opening and closing parentheses, just after the function
name followed by a colon.
After defining the function name and arguments(s) a block of
program statement(s) start at the next line and these
statement(s) must be indented.
Call a function
Calling a function in Python is similar to other programming languages, using the
function name, parenthesis (opening and closing) and parameter(s). See the
syntax, followed by an example.
Syntax:
function_name(arg1, arg2)
Python Packages
Suppose you have developed a very large application that includes many
modules.
As the number of modules grows, it becomes difficult to keep track of them all if
they are dumped into one location. This is particularly so if they have similar
names or functionality. You might wish for a means of grouping and organizing
them.
Packages allow for a hierarchical structuring of the module namespace using dot
notation. In the same way that modules help avoid collisions between global
variable names, packages help avoid collisions between module names.
Creating a package is quite straightforward, since it makes use of the operating
system’s inherent hierarchical file structure. Consider the following arrangement:
In the same way, a package in Python takes the concept of the
modular approach to next logical level.
As you know, a module can contain multiple objects, such as
classes, functions, etc. A package can contain one or more
relevant modules.
Physically, a package is actually a folder containing one or more
module files.
Let's create a package named mypackage, using
the following steps:
•Create a new folder named D:MyApp.
•Inside MyApp, create a subfolder with the name
'mypackage'.
•Create an empty __init__.py file in the
mypackage folder.
Predefined Package
1. NumPy and SciPy are two predefined package
2. You need to install both package later on .
What is NumPy?
NumPy is a Python library used for working with
arrays.
It also has functions for working in domain of
linear algebra, fourier transform, and matrices.
NumPy was created in 2005 by Travis Oliphant. It
is an open source project and you can use it freely.
NumPy stands for Numerical Python.
.
Why Use NumPy?
In Python we have lists that serve the purpose of
arrays, but they are slow to process.
NumPy aims to provide an array object that is up to
50x faster than traditional Python lists.
The array object in NumPy is called ndarray, it
provides a lot of supporting functions that make
working with ndarray very easy.
Arrays are very frequently used in data science,
where speed and resources are very important
SciPy Introduction
What is SciPy?
SciPy is a scientific computation library that
uses NumPy underneath.
SciPy stands for Scientific Python.
It provides more utility functions for optimization, stats and
signal processing.
Like NumPy, SciPy is open source so we can use it freely.
SciPy was created by NumPy's creator Travis Olliphant.
Why Use SciPy?
If SciPy uses NumPy underneath, why can we not just use
NumPy?
SciPy has optimized and added functions that are frequently
used in NumPy and Data Science.
Create a NumPy ndarray Object
NumPy is used to work with arrays. The array object in NumPy is
called ndarray.
We can create a NumPy ndarray object by using the array() function.
Example
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
print(type(arr))
Import SciPy
Once SciPy is installed, import the SciPy module(s) you want to use in
your applications by adding the from scipy import module statement:
from scipy import constants
Now we have imported the constants module from SciPy, and the
application is ready to use it:
Example
How many cubic meters are in one liter:
from scipy import constants
print(constants.liter)
Matplotlib Pyplot
Matplotlib is an amazing visualization library in Python for 2D
plots of arrays. Matplotlib is a multi-platform data visualization
library built on NumPy arrays and designed to work with the
broader SciPy stack.
It was introduced by John Hunter in the year 2002.
One of the greatest benefits of visualization is that it allows us
visual access to huge amounts of data in easily digestible visuals.
Matplotlib consists of several plots like line, bar, scatter,
histogram etc.
Installation :
Windows, Linux and macOS distributions have matplotlib and most of its
dependencies as wheel packages. Run the following command to
install matplotlib package :
python -mpip install -U matplotlib
Importing matplotlib :
from matplotlib import pyplot as plt or import matplotlib.pyplot as plt
ch 2. Python module

ch 2. Python module

  • 2.
    Introduction :- If youquit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a script. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program. To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).
  • 3.
    Modules What is aModule? Consider a module to be the same as a code library. A file containing a set of functions you want to include in your application. Create Modules 1. writing a module means simply creating a file which can contains python definitions .The file name is the module name with the extension .py. To include module in a file , use import statements. 2. Create a first fiel as apython program with extension as.py . This is your module file where we can write a function which performs some task . 3. Create a second file int the same directory called amin file where we can import the module at the top of file and call the functions . For.Example
  • 4.
    Create a Module Tocreate a module just save the code you want in a file with the file extension .py: Example Save this code in a file named mymodule.py def greeting(name): print("Hello, " + name)
  • 5.
    Use a Module Nowwe can use the module we just created, by using the import statement: Example Import the module named mymodule, and call the greeting function: import mymodule mymodule.greeting("Jonathan")
  • 6.
    Built in Module 1.module is a collection of pyhton objects such as functions ,classes and so on . Python interpreter is bundled with a standard libarary consisting of alrge numbers of built in modules . 2. Built in modules are generally written in C and bundled with python interpreter in precompiled form . A built in Modules may be a python script with .py extension . 3. In addition to built-in functions, a large number of pre- defined functions are also available as a part of libraries bundled with Python distributions. These functions are defined in modules are called built-in modules.
  • 7.
    1. Math andcmath module Python math Module 1.Python has a built-in module that you can use for mathematical tasks. 2. The math module has a set of methods and constant. 3. The math module gives us access to hyperbolic , trignometric , and logarithmetoic functions for real numbers and cmath module allows us to work with mathematical functions
  • 8.
    Arithmetic Functions These functionsperform various arithmetic operations like calculating the floor, ceiling, or absolute value of a number using the floor(x), ceil(x), and fabs(x) functions respectively. The function ceil(x) will return the smallest integer that is greater than or equal to x. Similarly, floor(x) returns the largest integer less than or equal to x. The fabs(x) function returns the absolute value of x. You can also perform non-trivial operations like calculating the factorial of a number using factorial(x).
  • 9.
    import math math.ceil(1.001) #returns 2 math.floor(1.001) # returns 1 math.factorial(10) # returns 3628800 math.gcd(10,125) # returns 5 math.trunc(1.001) # returns 1 math.trunc(1.999) # returns 1
  • 10.
    Trigonometric Functions You cancalculate sin(x), cos(x), and tan(x) directly using this module. However, there is no direct formula to calculate cosec(x), sec(x), and cot(x), but their value is equal to the reciprocal of the value returned by sin(x), cos(x), and tan(x) respectively.
  • 11.
    import math math.sin(math.pi/4) #returns 0.7071067811865476 math.cos(math.pi) # returns -1.0 math.tan(math.pi/6) # returns 0.5773502691896257 math.hypot(12,5) # returns 13.0 math.atan(0.5773502691896257) # returns 0.5235987755982988 math.asin(0.7071067811865476) # returns 0.7853981633974484
  • 12.
    Hyperbolic functions areanalogs of trigonometric functions that are based on a hyperbola instead of a circle. I n trigonometry, the points (cos b, sin b) represent the points of a unit circle. In the case of hyperbolic functions, the points (cosh b, sinh b) represent the points that form the right half of an equilateral hyperbola. Just like the trigonometric functions, you can calculate the value of sinh(x), cosh(x), and tanh(x) directly. The rest of the values can be calculated using various relations among these three values. There are also other functions like asinh(x), acosh(x), and atanh(x), which can be used to calculate the inverse of the corresponding hyperbolic values. Hyperbolic functions
  • 13.
    import math math.sinh(math.pi) #returns 11.548739357257746 math.cosh(math.pi) # returns 11.591953275521519 math.cosh(math.pi) # returns 0.99627207622075 math.asinh(11.548739357257746) # returns 3.141592653589793 math.acosh(11.591953275521519) # returns 3.141592653589793 math.atanh(0.99627207622075) # returns 3.141592653589798
  • 14.
    In Python, thereis a module called Decimal, which is used to do some decimal floating point related tasks. This module provides correctly-rounded floating point arithmetic. To use it at first we need to import it the Decimal standard library module. import decimal 2. Decimal Module
  • 15.
    The square rootfunction sqrt() and Exponent function exp() The sqrt() method is used to calculate the square root of a given decimal type object. And the exp() method returns the e^x value for the given x as Decimal number. Python in its definition provides certain methods to perform faster decimal floating point arithmetic using the module “decimal”. Important operations on Decimals 1. sqrt() :- This function computes the square root of the decimal number. 2. exp() :- This function returns the e^x (exponent) of the decimal number.
  • 16.
    Example Code #Perform sqrt()and exp() methods import decimal my_dec = decimal.Decimal(25.36) print(my_dec) #Find Square Root print('Square Root is: ' + str(my_dec.sqrt())) #Find e^x print('e^x is: ' + str(my_dec.exp())) Output 25.3599999999999994315658113919198513031005859375 Square Root is: 5.035871324805668565859161094 e^x is: 103206740212.7314661465187086
  • 17.
    3.Fraction Module This moduleprovides support for rational number arithmetic. It allows to create a Fraction instance from integers, floats, numbers, decimals and strings. Fraction Instances : A Fraction instance can be constructed from a pair of integers, from another rational number, or from a string. Fraction instances are hashable, and should be treated as immutable.
  • 19.
    4. Python -Statistics Module The statistics module provides functions to mathematical statistics of numeric data. The following popular statistical functions are defined in this module.
  • 22.
    5. Time Functionsin Python What is Tick? Time intervals are floating-point numbers in units of seconds. Particular instants in time are expressed in seconds since 00:00:00 hrs January 1, 1970(epoch). There is a popular time module available in Python which provides functions for working with times, and for converting between representations. The function time.time() returns the current system time in ticks since 00:00:00 hrs January 1, 1970(epoch). Epoch:- a particular period of time in history or a person's life
  • 23.
    1.. time() :-This function is used to count the number of seconds elapsed since the epoch.
  • 25.
    2. gmtime(sec) :-This function returns a structure with 9 values each representing a time attribute in sequence. It converts seconds into time attributes(days, years, months etc.) till specified seconds from epoch. If no seconds are mentioned, time is calculated till present. 3. asctime(“time”) :- This function takes a time attributed string produced by gmtime() and returns a 24 character string denoting time. 4. ctime(sec) :- This function returns a 24 character time string but takes seconds as argument and computes time till mentioned seconds. If no argument is passed, time is calculated till present. 5. sleep(sec) :- This method is used to halt the program execution for the time specified in the arguments.
  • 26.
    6. Python DatetimeModule A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects. Example Import the datetime module and display the current date: Example :- import datetime x = datetime.datetime.now() print(x) Output:-
  • 27.
    Creating Date Objects Example: import datetime x = datetime.datetime.now() print(x.year) print(x.strftime("%A")) Output :-
  • 28.
    Python defines aninbuilt module “calendar” which handles operations related to the calendar. Operations on the calendar : 1. calendar(year, w, l, c):- This function displays the year, the width of characters, no. of lines per week, and column separations. 2. firstweekday() :- This function returns the first week day number. By default 0 (Monday). 7 . Calendar
  • 31.
    8.Python - sysModule Python sys module The python sys module provides functions and variables which are used to manipulate different parts of the Python Runtime Environment. It lets us access system-specific parameters and functions. import sys 1. sys.modules This function provides the name of the existing python modules which have been imported
  • 33.
    Input and Outputusing sys The sys modules provide variables for better control over input or output. We can even redirect the input and output to other devices. This can be done using three variables – •stdin •stdout •Stderr 1. stdin: It can be used to get input from the command line directly. It used is for standard input. It internally calls the input() method. It, also, automatically adds ‘n’ after each sentence. Example:
  • 36.
    stdout: A built-infile object that is analogous to the interpreter’s standard output stream in Python. stdout is used to display output directly to the screen console. Output can be of any form, it can be output from a print statement, an expression statement, and even a prompt direct for input. By default, streams are in text mode. In fact, wherever a print function is called within the code, it is first written to sys.stdout and then finally on to the screen.
  • 37.
  • 38.
    stderr: Whenever anexception occurs in Python it is written to sys.stderr. Example: output
  • 39.
    9.Python Random Module PythonRandom module is an in-built module of Python which is used to generate random numbers. These are pseudo-random numbers means these are not truly random. This module can be used to perform random actions such as generating random numbers, print random a value for a list or string, etc. Example: Printing a random value from a list The random module has a set of methods:
  • 40.
    The randrange() methodreturns a randomly selected element from the specified range. Syntax random.randrange(start, stop, step)
  • 42.
    User defined function InPython, a user-defined function's declaration begins with the keyword def and followed by the function name. The function may take arguments(s) as input within the opening and closing parentheses, just after the function name followed by a colon. After defining the function name and arguments(s) a block of program statement(s) start at the next line and these statement(s) must be indented.
  • 43.
    Call a function Callinga function in Python is similar to other programming languages, using the function name, parenthesis (opening and closing) and parameter(s). See the syntax, followed by an example. Syntax: function_name(arg1, arg2)
  • 44.
    Python Packages Suppose youhave developed a very large application that includes many modules. As the number of modules grows, it becomes difficult to keep track of them all if they are dumped into one location. This is particularly so if they have similar names or functionality. You might wish for a means of grouping and organizing them. Packages allow for a hierarchical structuring of the module namespace using dot notation. In the same way that modules help avoid collisions between global variable names, packages help avoid collisions between module names. Creating a package is quite straightforward, since it makes use of the operating system’s inherent hierarchical file structure. Consider the following arrangement:
  • 45.
    In the sameway, a package in Python takes the concept of the modular approach to next logical level. As you know, a module can contain multiple objects, such as classes, functions, etc. A package can contain one or more relevant modules. Physically, a package is actually a folder containing one or more module files.
  • 46.
    Let's create apackage named mypackage, using the following steps: •Create a new folder named D:MyApp. •Inside MyApp, create a subfolder with the name 'mypackage'. •Create an empty __init__.py file in the mypackage folder.
  • 50.
    Predefined Package 1. NumPyand SciPy are two predefined package 2. You need to install both package later on . What is NumPy? NumPy is a Python library used for working with arrays. It also has functions for working in domain of linear algebra, fourier transform, and matrices. NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it freely. NumPy stands for Numerical Python.
  • 51.
    . Why Use NumPy? InPython we have lists that serve the purpose of arrays, but they are slow to process. NumPy aims to provide an array object that is up to 50x faster than traditional Python lists. The array object in NumPy is called ndarray, it provides a lot of supporting functions that make working with ndarray very easy. Arrays are very frequently used in data science, where speed and resources are very important
  • 52.
    SciPy Introduction What isSciPy? SciPy is a scientific computation library that uses NumPy underneath. SciPy stands for Scientific Python. It provides more utility functions for optimization, stats and signal processing. Like NumPy, SciPy is open source so we can use it freely. SciPy was created by NumPy's creator Travis Olliphant. Why Use SciPy? If SciPy uses NumPy underneath, why can we not just use NumPy? SciPy has optimized and added functions that are frequently used in NumPy and Data Science.
  • 53.
    Create a NumPyndarray Object NumPy is used to work with arrays. The array object in NumPy is called ndarray. We can create a NumPy ndarray object by using the array() function. Example import numpy as np arr = np.array([1, 2, 3, 4, 5]) print(arr) print(type(arr))
  • 54.
    Import SciPy Once SciPyis installed, import the SciPy module(s) you want to use in your applications by adding the from scipy import module statement: from scipy import constants Now we have imported the constants module from SciPy, and the application is ready to use it: Example How many cubic meters are in one liter: from scipy import constants print(constants.liter)
  • 55.
    Matplotlib Pyplot Matplotlib isan amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002. One of the greatest benefits of visualization is that it allows us visual access to huge amounts of data in easily digestible visuals. Matplotlib consists of several plots like line, bar, scatter, histogram etc.
  • 56.
    Installation : Windows, Linuxand macOS distributions have matplotlib and most of its dependencies as wheel packages. Run the following command to install matplotlib package : python -mpip install -U matplotlib Importing matplotlib : from matplotlib import pyplot as plt or import matplotlib.pyplot as plt