You are on page 1of 9

Digital Image Processing

Ma’am Amna Waheed


LAB NO 2

NAME::Irfan Haider
CLASS: BCE-7
ENROLLMENT NO: 01-132182-035
DEPARTMENT OF COMPUTER ENGINEERING
BAHRIA UNIVERSITY | ISLAMABAD CAMPUS
Lab Journal - Lab 2

Name: Irfan Haider______________________________

Enrollment #: 01_132182_035______________________________

Class: BCE 7____________________________


Title
Introduction to digit image processing using python

Objective

This introductory lab is intended to familiarize students with the basics of Python, a high level
computing language for algorithmic development, data visualization and data analysis. The
students will also be introduced to manipulation of matrices and arrays in Python.

Task 1:

1 Given a matrix A, write statement(s) to find the sum of the diagonal elements of A.

2 Using the colon operator, create a vector V with values [0,1,2,…, 100].
3 Extract the second column of a matrix and store it in a vector.

4 Extract the 1st, 3rd and 5th row of matrix into another matrix.

5 Multiply each element of a matrix A by 2 and store the result in matrix B.


Task 2
1 A1=np.array([[2,4,6],[8,10,8],[2,10,4]])
print(np.sum(A1, axis=0)) print(np.sum(A1, axis=1))
print(np.sum(A1))
Note: axis 0” represents rows and “axis 1” represents columns.

2 A1=np.array([[2,4,6],[8,10,8],[2,10,4]])
ss=A1[range(0,2),:] print(np.transpose(ss))
3 A=np.array([[1,2],[3,4]])
B=np.array([[5,6],[7,8]])
A*B
A.dot(B)

Task 1
Write a Python program which create 2x2 matrix A. Find the determinant and inverse of this matrix.
Multiply the matrix with its inverse and display the result.
Code
import numpy as np

mat = np.random.randint(10, size=(2, 2))


print("ORIGINAL MATRIX: ", mat)
print("DETERMINANT OF MATRIX: ")
print(np.linalg.det(mat))
print("INVERSE OF MATRIX : ")
invmat = np.linalg.inv(mat)
print(invmat)
print("MULTIPLICATION OF ORIGINAL MATRIX WITH INVERSE:::")
res = np.dot(mat,invmat)
print(res)

Task 2
Write a program that loads iris data set (that comes with Python(sklearn)): from sklearn import
datasets iris = datasets.load_iris() The iris data set comprises data of 3 different flower species of the
Iris plant. The first four columns of the data set represent sepal length, sepal width, petal length and
petal width respectively. The last column is a label which tells the type of flower (1,2 or 3). The first
50 rows correspond to type 1, the next 50 rows to type 2 and the last 50 rows to type 3. Find the
mean and standard deviation of the sepal length, sepal width, petal length and petal width for each
category of iris
Code
import pandas as pd

ds = pd.read_csv(r'E:\ mutlub\bin\iris_csv.csv')

ds.head()

print(ds[ds['class'] == 'Irissetosa']['sepallength'].mean())

print(ds[ds['class'] == 'Irissetosa']['sepalwidth'].std())

print(ds[ds['class'] == 'Irissetosa']['petallength'].mean())

print(ds[ds['class'] == 'Irissetosa']['petalwidth'].std())

print(ds[ds['class'] == 'Irisversicolor']['sepallength'].mean())

print(ds[ds['class'] == 'Irisversicolor']['sepalwidth'].std())

print(ds[ds['class'] == 'Irisversicolor']['petallength'].mean())

print(ds[ds['class'] == 'Irisversicolor']['petalwidth'].std())

print(ds[ds['class'] == 'Irisvirginica']['sepallength'].mean())
print(ds[ds['class'] == 'Irisvirginica']['sepallength'].std())

print(ds[ds['class'] == 'Irisvirginica']['petallength'].mean())

print(ds[ds['class'] == 'Irisvirginica']['petalwidth'].std())
Conclusion
In this lab I have learnt how to import the dataset and find their mean

You might also like