hello everyone welcome to the semicolon
this tutorial is a part of the series
data analytics with Python. today we're
going to learn about numpy and matplotlib
libraries. numpy is an extension
to python which adds multi-dimensional
array support to python. the numpy array
come in really handy for data analytics
purposes apart from data analytics one
of the important roles of data scientist
is to visualize data and matplotlib is a
library which gives us the superpowers
to plot beautiful graphs. let's have a
brief look at both of these in this
video. let's start learning about the
numpy library. We import the numpy
library by typing import numpy as np. now
we can call all the functions of numpy
library by using np. we create a list of
some numbers and then pass it to the
function np dot array so what we have
now is a numpy array. so we when we
multiply it by a scalar it looks
something like this, it gets multiplied
each and every element gets multiplied
by the scalar. if you multiply it with
the array with the numpy array of same
dimension then it is element wise
multiplication which you can try it yourself.
let's try to generate a sequence of
numbers using the a range function. when
we pass two integers to the a range
function, the first integer is a starting
point and the last integer which is not
included is the ending point. so we get
when we pass one and ten we get
the numbers from one to nine and if
we want to generate numbers with a
constant distance then, we just have to
type one more we just have to pass in
one more parameter which gives the
distance. so let's generate numbers from
point 1 to 1.2 and give the gap as point
1 so we get all the numbers from point 1
to 1.1 with a gap of point 1. now, let's
look at how we create multi-dimensional
arrays.
so we pass a list of lists through the
same function np dot array store it in b.
so what we have is our own numpy array
which is multi-dimensional. so you can
check the dimensional dimensionality
of array by typing b dot ndime and also
you can do the same thing with a so, the
dimension of b is two, and the dimension
of a is one. now we can also calculate
the shape of the numpy array by passing
it through the shape function, np dot
shape and b is a two cross two array as
you could see when we printed it out and
a is a four cross one array. so this how we
can check the shape and dimension of our
arrays. let's see how we can access the
values from the indexing. when we pass in
one value or the first value, the first
index is, it is for the rows so, b of 0
gives us the row b of one would give us
the second row b of 0 gave us the first
row, and if we type another indexing
another layer of indexing, b of 0 of 0 we
get the first element of the first row
and we can select a range of indexes
as well by typing 1 colon 3 we get the
numbers which are indexed at 1 and 2. so
3 is not included as in numpy the ending
point is not generally included. so now
let's look at how we generate random
numbers. we type np dot random dot
rand n and pass in the size of the
matrix in which we want to generate our
random number, and this is what we have
as our random matrix.
let's start learning about the matplotlib
library. so matplotlib is a very
important library for plotting graphs
and is very important in data
visualization. we import matplotlib dot
pyplot as plt and then when we want to
plot a graph, we create a list and pass
it through plt dot plot, and if we do not
pass the list it shows an empty graph
but then when we pass on the list this
what we have, it plots the points to the
y axis by default, when we do not pass
the points in the x-axis. you can change
the labels of x axis and y axis using
the functions plt dot ylabel and
passing the label as a string, and you
can do the same thing with x axis as
well. you can also pass in the points of
x axis. the first list is generally
considered as the points of x axis and
the second list is considered as the
points in y axis, and when we pass it
through the plot function this is how
our graph looks like. so we can again
add xlabel ylabel or you could
change the dimensions of the axis so you
you have to pass a list through the
axis function and the first two
elements of the list represents the
range of the x-axis and these next two
elements of the list represents the
range of the y axis. so this is what our
graph looks like after we incorporate
the change in axis.
then, you can plot points instead of a
straight line and we can specify color
by using R B G, and specify the shape
using O so, when we type R O we get red
circles as points, when we type R minus
we get connected lines and when we type
R and the symbol which is used to
represent power or exponent, we get
triangles. you can replace R with B and
G as well to get red blue and green
colors. so this is how it looks like when
we can color our graph. you can also plot
multiple graphs with different colors.
let's plot a with a square with red
circles and this how our graph looks
like, then let's add a and a cube and
plot it with blue triangles, and you have
to pass it in string and that is why
the error. and this how two graph looks
together, you can pass in two graphs through
the pyplot function. you can change the
shape, color and everything. so this is
what we have for the matplotlib
library which will be useful for our
course with data analytics. hit the like
button if you enjoyed this video, hit the
subscribe button if you want to keep
watching more and more of videos like
this thank you.