Professional Documents
Culture Documents
AI Lab
AI Lab
What is numpy?
Numpy is a general-purpose array-processing package. It provides a high-performance
multidimensional array object, and tools for working with these arrays.
It is the fundamental package for scientific computing with Python. It contains various features
including these important ones:
A powerful N-dimensional array object
Sophisticated (broadcasting) functions
Useful linear algebra, Fourier transform, and random number capabilities
How it is installed?
To install it on Ubuntu, run the following commands in terminal.
sudo apt-get install python-pip3
sudo pip3 install numpy scipy
Where it is used?
Python does not have built-in support for Arrays, but Python lists can be used instead:
Next, for the 2D, 3D etc arrays in Numpy to calculate big data in terms of including columns and
rows:
Code Example?
import numpy as np
# Creating array object
arr = np.array( [[ 1, 2, 3],
[ 4, 2, 5]] )
# Printing type of arr object
print("Array is of type: ", type(arr))
# Printing array dimensions (axes)
print("No. of dimensions: ", arr.ndim)
# Printing shape of array
print("Shape of array: ", arr.shape)
# Printing size (total number of elements) of array
print("Size of array: ", arr.size)
# Printing type of elements in array
print("Array stores elements of type: ", arr.dtype)
Output :
Array is of type:
No. of dimensions: 2
Size of array: 6
Pandas
What Is Pandas?
Pandas is a Python package providing fast, flexible, and expressive data structures designed to
make working with structured (tabular, multidimensional, potentially heterogeneous) and time
series data both easy and intuitive. It aims to be the fundamental high-level building block for
doing practical, real world data analysis in Python.
How it is Installed?
Pandas is install in windows using the following query in command line:
pip install pandas
Where it is used?
In computer programming, pandas is a software library written for the Python programming
language for data manipulation and analysis. In particular, it offers data structures and operations
for manipulating numerical tables and time series. It is free software released under the three-
clause BSD license. Pandas is an open source Python package that provides numerous tools for
data analysis. The package comes with several data structures that can be used for many different
data manipulation tasks. It also has a variety of methods that can be invoked for data analysis,
which comes in handy when working on data science and machine learning problems in Python.
This is used to map values from two series having one column
4 same. For mapping two series, the last column of the first
pandas.map() series should be same as index column of the second series,
also the values should be unique.
Code Example?
# Program to create Dataframe of three series
import pandas as pd
s1 = pd.Series([1, 3, 4, 5, 6, 2, 9]) # Define series 1
s2 = pd.Series([1.1, 3.5, 4.7, 5.8, 2.9, 9.3]) # Define series 2
s3 = pd.Series(['a', 'b', 'c', 'd', 'e']) # Define series 3
Data ={'first':s1, 'second':s2, 'third':s3} # Define Data
dfseries = pd.DataFrame(Data) # Create DataFrame
Output
Matplotlib
What is Matplotlib function?
matplotlib.pyplot is a collection of command style functions that make matplotlib work like
MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a
plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.
How it is installed?
Matplotlib is install in windows using the following query in command line:
pip install matplotlib
Where it is used?
matplotlib. pyplot is a plotting library used for 2D graphics in python programming language. It
can be used in python scripts, shell, web application servers and other graphical user interface
toolkits. There are several toolkits which are available that extend python
matplotlib functionality
Code Example?
# importing matplotlib module
from matplotlib import pyplot as plt
# x-axis values
x = [5, 2, 9, 4, 7]
# Y-axis values
y = [10, 5, 8, 4, 2]
# Function to plot
plt.plot(x,y)
# function to show the plot
plt.show()
Output