Professional Documents
Culture Documents
Dip Lab 1
Dip Lab 1
Dip Lab 1
Lab -01
Student Name:________________________________
ID:__________________________________________
Date of Submission:____________________________
Objective
Import numpy as np
a=np.array([[1,2,3],[2,3,4],[5,6,7]])
Print (a)
Print(“\n”)
A=a[0,0]+a[1,1]+a[2,2]
M=[a[0,0],a[1,1],a[2,2]]
N=np.sum(m)
Print(N)
Arr=np.array(range(0,100))
A=Arr[:]
Print(A)
Import numpy as np
a=np.array([[1,2,3],[2,3,4],[5,6,7]])
A=a[:,1]
Print(A)
4. Extract the 1st, 3rd, and 5th row of matrix into another matrix.
Import numpy as np
a=np.array([[1,2,3,4,5],[2,3,4,5,6],[5,6,7,9,10]])
A=np.array([a[:,0], a[:,2],a[:,4]])
Print(A)
Import numpy as np
a=np.array([[1,2,3,4,5],[2,3,4,5,6],[5,6,7,9,10]])
print(a,”\n”)
A=a*2
Print(A)
Print(np.sum(A1, axis=0))
Print(np.sum(A1, axis=1))
Print(np.sum(A1))
2. A1 = np.array([[1,2,3],[2,4,5],[6,7,8]])
Ss=A1[range(0,2),:]
Print(np.transpose(ss))
Import numpy as np
A=np.array([[1,2],[3,4]])
Print(A)
Print(np.linalg.det(A))
Print(np.linalg.inv(A))
Print(np.linalg.inv(A) * A)
Exercise 2:
Write a program that load iris dataset ( that comes with python(sklearn)):
Iris=datasets.load_iris()
The iris datasets comprises data of 3 different flower species of their iris
plant. The first four columns of the dataset represent sepal length , sepal
width, petal length and petal width respectively. The last column is a label
which tells the type of flowers(1,2, or 3). The first 50 rows define the type
1, the next 50 rows defines the type 2 and the last 50 rows define the type
5. Find the mean and standard deviation of the sepal length , sepal width,
petal length and petal width for each type of iris flowers.
Print(__docs__)
Import numpy as n
Iris= datasets.load_iris()
Y=iris.target
x_min, x_max = X[:, 0].min() - 0.5, X[:, 0].max() + 0.5
y_min, y_max = X[:, 1].min() - 0.5, X[:, 1].max() + 0.5
plt.gray()
plt.figure(figsize=(8,6))
plt.ylabel(‘sepal width’)
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
plt.xticks(())
plt.yticks(())
x_min, x_max = X[:, 2].min() - 0.5, X[:, 2].max() + 0.5
y_min, y_max = X[:, 3].min() - 0.5, X[:, 3].max() + 0.5
plt.gray()
plt.figure(figsize=(8,6))
plt.ylabel(‘Petal width’)
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
plt.xticks(())
plt.yticks(())
plt.show()
The first 50 datasets for the type1 flowers
Dd=(type1)
Q0=np.mean(type1[:,0])
Q1= np.mean(type1[:,1])
Q2= np.mean(type1[:,2])
Q3= np.mean(type1[:,3])
M=np.mean([Q0,Q1,Q2,Q3])