FDS Lab Record
FDS Lab Record
AIM :
ALGORITHM :
PROGRAM :
arr=[7,3,1,2,5]
arr.sort()
print(arr)
OUTPUT:
[1, 2, 3, 5, 7]
RESULT:
Thus the program was executed successfully and the output is verified.
Ex.No. : 1(b) Sorting The Array elements in Descending Order
Date :
AIM :
ALGORITHM :
PROGRAM:
arr=[7,3,1,2,5]
arr.sort(reverse=true)
print(arr)
OUTPUT:
[7, 5, 3, 2, 1]
RESULT:
Thus the program was executed successfully and the output is verified.
Ex.No. : 1(c) Addition and Subtraction Operations in matrix using Numpy
arrays
Date :
AIM :
ALGORITHM :
PROGRAM :
import numpy as np
a=np.array([1,2],[2,1])
b=np.array([3,4],[4,3])
r1=np.add(a,b)
r2=np.sub(a,b)
print(r1)
print(r2)
OUTPUT:
[[4 6]
[6 4]]
[[-2 -2]
[2 2]]
RESULT:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
a=[[2,4],[6,8]]
b=[[1,3],[5,7]]
print(np.matmul(a,b))
OUTPUT:
[[22 34]
[46 74]]
RESULT:
Date:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
a=np.array([1,2],[3,4])
b=a.transpose()
print(b)
OUTPUT:
[[1 3]
[2 4]]
RESULT:
Date :
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
arr=np.array([1,3,5,7,9,11,13,15])
b=np.reshape(4,2)
print(b)
OUTPUT:
[[1 3]
[5 7]
[9 11]
[13 15]]
RESULT:
Date:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
a=np.array([1,0,1,1,0])
b=astype(bool)
print(b)
OUTPUT:
Date:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
b=a.astype(int)
print(b)
OUTPUT:
[1 7 6 2]
RESULT:
Date:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
a=np.array([10,20,30])
b=np.hstack(a)
c=np.vstack(a)
print(“Horizontal stack”)
print(b)
print(“Vertical stack”)
print(c)
OUTPUT:
Horizontal stack
[10 20 30]
Vertical stack
[[10]
[20]
[30]]
RESULT:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
a=np.arange(0,50,2)
print(a)
OUTPUT:
[0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48]
RESULT:
AIM:
To write a numpy program to get the position where the elements of two
numpy arrays match
ALGORITHM:
PROGRAM:
import numpy as np
a=np.array([2,3,5,5])
b=np.array([2,4,5,6])
print(np.where(a==b))
OUTPUT:
array([0,2],dtype=int64)
RESULT:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
a=np.count_nonzero(np.linspace(2,3))
print(a)
OUTPUT:
50
RESULT:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
from numpy import random
a=np.random.randint(1,20,10)
print(a)
OUTPUT:
[3 6 14 1 19 10 4 1 11 17]
RESULT:
AIM:
To write a python program to find sine and cosine of an angle using numpy
ALGORITHM:
PROGRAM:
import numpy as np
x=np.sin(np.pi/2)
y=np.cos(np.pi)
print(x)
print(y)
OUTPUT:
1.0
-1.0
RESULT:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
from numpy import random
a=np.random.normal(size=3)
print(a)
OUTPUT:
RESULT:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
a=np.array([1, 8, 4])
print(np.exp(a))
print(np.log(a))
print(np.sqrt(a))
print(np.power(a,3))
OUTPUT:
RESULT:
like object
Date :
AIM:
ALGORITHM :
PROGRAM :
import pandas as pd
ds=pd.Series([1,3,5,7])
print(ds)
OUTPUT :
0 1
1 3
2 5
3 7
dtype : int64
RESULT :
Date :
AIM :
ALGORITHM :
PROGRAM :
import pandas as pd
a=pd.Series([2,4,6,8])
b=pd.Series([1,3,5,7])
c=a+b
d=a-b;
e=a*b
f=a/b
print(“Series 1)
print(a)
print(“Series 2”)
print(b)
print(“Sum”)
print(c)
print(“Difference”)
print(d)
print(“Product”)
print( e)
print(“Quotient”)
print(f)
OUTPUT :
Series 1
0 2
1 4
2 6
3 8
dtype=int64
Series 2
0 1
1 3
2 5
3 7
dtype=int64
Sum
0 3
1 7
2 11
3 15
dtype=int64
Difference
0 1
1 1
2 1
3 1
dtype=int64
Product
0 2
1 12
2 30
3 56
dtype=int64
Quotient
0 2.0000
1 1.3333
2 1.2000
3 1.1428
dtype=float64
RESULT :
Date :
AIM :
ALGORITHM :
PROGRAM :
import pandas as pd
exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],
‘score’ : [12,9,16,9,20],
‘attempt’ : [1,3,2,3,2],
‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}
Labels=[‘a’,’b’,’c’,’d’,’e’]
df=pd.DataFrame(exam,index=Labels)
print(df)
OUTPUT :
a Joy 12 1 yes
b Diya 9 3 no
c Anu 16 2 yes
d John 9 3 no
e Radha 20 2 yes
RESULT :
Date :
AIM :
To write a pandas program to create and display the first rows of the
dataframe.
ALGORITHM :
PROGRAM :
import pandas as pd
exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],
‘score’ : [12,9,16,9,20],
‘attempt’ : [1,3,2,3,2],
‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}
Labels=[‘a’,’b’,’c’,’d’,’e’]
df=pd.DataFrame(exam,index=Labels)
print(df.iloc[0:3])
OUTPUT :
a Joy 12 1 yes
b Diya 9 3 no
c Anu 16 2 yes
RESULT :
Date :
AIM :
ALGORITHM :
PROGRAM :
import pandas as pd
exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],
‘score’ : [12,9,16,9,20],
‘attempt’ : [1,3,2,3,2],
‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}
Labels=[‘a’,’b’,’c’,’d’,’e’]
df=pd.DataFrame(exam,index=Labels)
print(df[[‘name’,’score’]])
OUTPUT :
name score
a Joy 12
b Diya 9
c Anu 16
d John 9
e Radha 20
RESULT :
Date :
AIM :
ALGORITHM:
PROGRAM :
import pandas as pd
exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],
‘score’ : [12,9,16,9,20],
‘attempt’ : [1,3,2,3,2],
‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}
Labels=[‘a’,’b’,’c’,’d’,’e’]
df=pd.DataFrame(exam,index=Labels)
rows=len(df.axes[0])
cols=len(df.axes[1])
print(“Rows = “,rows)
print(“Columns = “,cols)
OUTPUT :
Rows = 5
Columns = 4
RESULT :
Date :
AIM :
To write a pandas program to get all elements in array using numpy which
is less than n.
ALGORITHM :
PROGRAM :
import numpy as np
n=6
print(a[a<n])
OUTPUT :
[5.4, 4.9, 2.5, 1.2]
RESULT :
Date :
AIM :
ALGORITHM :
PROGRAM :
import pandas as pd
df=pd.DataFrame({‘A’ :
[12,67,90,45,89,34,79,45,67,12,48,50,23,47,56,89,79,45,80,57]})
count=fd.groupby([‘A’]).size()
print(count)
OUTPUT :
12 2
23 1
34 1
45 3
47 1
48 1
50 1
56 1
57 1
67 2
79 2
80 1
89 2
90 1
dtype: int64
RESULT :
Date :
AIM :
ALGORITHM :
PROGRAM :
import pandas as pd
df=DataFrame({‘emp_id’:[ e01, e03, e07, e08, e19, e25, e10, e31, e45, e34];
‘emp_name’:[‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’],
‘salary’:[12000,18000,30000,70000,50000,55000,45000,25000,30000,60000],
print(“Standard deviation”,df.std())
print(“Variance”,df.var())
OUTPUT:
Mean 39500.0
Variance 3.711667e+08
RESULT :
DATE:
AIM:
ALGORITHM:
PROGRAM:
import numpy as np
array = [24,53,53,36,21,84,64,34,77,54]
print(array)
r1 = np.mean(array)
print(“\nMean :”,r1)
r2 = np.std(array)
print(“SD :”,r2)
r3 = np.var(array)
print(“\nVariance:”,r3)
OUTPUT:
[24,53,53,36,21,84,64,34,77,54]
Mean : 50.0
SD : 20.208908926510603
Variance : 408.4
RESULT:
Thus the program was executed successfully and the output was verified.
Ex. No. :10 Scatterplots using matplotlib
Date:
AIM :
ALGORITHM:
PROGRAM :
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
plt.scatter(x,y)
plt.show()
OUTPUT :
RESULT:
Thus the program was executed successfully and the output was verified.
Ex. No. :11 Correlation using matplotlib
Date:
AIM :
ALGORITHM:
PROGRAM:
import sklearn
import numpy as np
import pandas as pd
y = pd.Series([1,2,3,4,3,5,4])
x = pd.Series([1,2,3,4,5,6,7])
correlation = y.corr(x)
print(correlation)
OUTPUT:
0.8603090020146067
RESULT:
Thus the program was executed successfully and the output was verified.
Ex. No. :12 Normal curves
Date:
AIM :
ALGORITHM:
PROGRAMS :
import numpy as np
import statistics
x_axis = np.arange(-26,20,0.01)
mean = statistics.mean(x_axis)
sd = statistics.stdev(x_axis)
plt.plot(x_axis,norm.pdf(x_axis,mean,sd))
plt.show()
OUTPUT:
RESULT :
Date:
AIM:
To write a python program that plots the given values in different types of
plots using matplotlib library.
ALGORITHM:
PROGRAM:
a = [1, 2, 3, 4, 5]
plt.plot(a)
plt.plot(b, "or")
plt.xlabel('Day ->')
plt.ylabel('Temp ->')
c = [4, 2, 6, 8, 3, 20, 13, 15]
ax = plt.gca()
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['left'].set_bounds(-3, 40)
plt.xticks(list(range(-3, 10)))
plt.show()
OUTPUT:
RESULT:
Thus the graph is plotted successfully using Matplotlib and the output
is verified.
Ex. No. :14 Creation of various types of graphs using
R- Programming
Date:
AIM:
ALGORITHM:
PROGRAM:
i)Plot
x <- c(1, 2, 3, 4, 5)
plot(x,y)
ii)Scatter plot
iii)Line plot
iv)Pie chart
library(plotrix)
col.main = "darkgreen")
v)Bar chart
vi)Histogram
v <- c(19, 23, 11, 5, 16, 21, 32, 14,19, 27, 39, 120, 40, 70, 90)
(i) (ii)
(iii)
(iv)
(v)
(vi)
RESULT: