-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day1_dhruvdhayal_ai.py
403 lines (338 loc) · 12 KB
/
Day1_dhruvdhayal_ai.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# -*- coding: utf-8 -*-
"""Day1_DhruvDhayal_AI.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1RsqcV02nwFqsVaetoZpiAJNGgpxcE3Mm
"""
#Day-1 Of_AI_ML_SUMMER_TRAINING.
print("\n --------------- Factorial Program! ---------------");
n=int(input("\n 1. Enter the Number in order to find it's Factorial: "));
fact=1;
for i in range(1,n+1):
i=i+1;
fact=fact*i;
print("\n --> Factorial of ",n," is: ",fact);
#Sum of the 'n' Numbers.
print("\n -------------- Sum of the Two or More Numbers! ------------------");
n=int(input("\n 1. Enter the Number in order to find it's Sum: "));
sum=0;
for i in range(1,n+1):
sum=sum+i;
i=i+1;
print("\t", sum);
print("\n --> Sum of ",n," is: ",sum);
#Adding of the Two Numbers.
#1. Manual Methods.
a=10;
b=90;
c=(a+b);
print("\n Total Sum of ",a," and ",b," is: ",c);
#2. User-Input Methods.
a=int(input("\n 1. Enter the First Number: "));
b=int(input("\n 2. Enter the Second Number: "));
result=(a+b);
print(f"\n\t--> Total Sum of {a} and {b} is: {result}");
#Using of the While Loop, or never-ending loop.
while(True):
print("Hello World"); #We, did not print this because it takes lot of memory and space, which may lead to bann of GoogleVColabLisecing.
#WAP a program to perform Arithmetic Operations (+,-,*,/), on the two no's entered by the user and perform operations on ot!
#(Operations has to been perfored)!
#Then, Ask the User a Question: Do, You Want to Continue?
#If 'n' Exists then its still performing the operations based on the True Valid-Conditions.
flag=True;
while(flag):
n1=int(input("\n 1. Enter the First Number: "));
n2=int(input("\n 2. Enter the Second Number: "));
ch=input("\n --> Enter the Operations You want to Perform: \n 1. Addition(+) \n2.Substraction(-) \n3.Multiplication(*) \n4.Division(/) \n\n");
#Checking the Operation in order to performs.
if(ch=='+'):
n3=(n1+n2);
print("\n\n --> Addition of (",n1,"+",n2,") is = ",n3);
elif(ch=='-'):
n3=(n1-n2);
print("\n --> Substraction of (",n1,"-",n2,") is = ",n3);
elif(ch==''):
n3=(n1*n2);
print("\n --> Multiplication of (",n1,"*",n2,") is = ",n3);
elif(ch=='/'):
if(n1>n2):
n3=(n1/n2);
print("\n --> Division of (",n1,"/",n2,") is = ",n3);
else:
n3=(n2/n1);
print("\n --> Division of (",n2,"/",n1,") is = ",n3);
else:
print("\n Invalid Input!");
#Main Driver Source Code Logic Of User-Input
#print("\n ----- Do, You Want to Still continiue Choose (Y/N): ");
user=input("\n----- Do, You Want to Still continiue Choose (Y/N): ");
flag=0;
if(user=="Y" or user=="y"):
flag=True;
print("\n Now, It's Again Executed!");
print("\n---------------------------------------\n");
else:
flag=False;
print("\n Program Terminated Thank You!");
print("\n---------------------------------------\n");
#Performing the Same Logic Program with the Functions.
#Starting Phase!
def values():
no1=int(input("\n 1. Enter the First Number: "));
no2=int(input("\n 2. Enter the Second Number: "));
ch=input("\n --> Enter the Operations You want to Perform: \n 1. Addition(+) \n2.Substraction(-) \n3.Multiplication(*) \n4.Division(/) \n\n");
return no1,no2,ch;
def operations(no1,no2,ch):
#Middle-Phase Performing Operations.
if(ch=='+'):
n3=(no1+no2);
print("\n\n --> Addition of (",no1,"+",no2,") is = ",n3);
elif(ch=='-'):
n3=(no1-no2);
print("\n --> Substraction of (",no1,"-",no2,") is = ",n3);
elif(ch=='*'):
n3=(no1*no2);
print("\n --> Multiplication of (",no1,"*",no2,") is = ",n3);
elif(ch=='/'):
if(no1>no2):
n3=(no1/no2);
print("\n --> Division of (",no1,"/",no2,") is = ",n3);
else:
n3=(no2/no1);
print("\n --> Division of (",no2,"/",no1,") is = ",n3);
else:
print("\n Invalid Input!");
def checking():
#Main-Driver Source Code.
user=input("\n --> Do, You Still Want to Continue? (Y/N): ");
if(user=="Y" or user=="y"):
return True;
print("\n Now, It's Again Executed!");
print("\n---------------------------------------\n");
else:
return False;
print("\n Program Terminated!");
print("\n---------------------------------------\n");
#Main Calling the Values of the Functions!
flag=True;
while(flag):
no1,no2,ch=values();
operations(no1,no2,ch);
flag=checking();
#Import third party Library in Python Instance.
#Command to install third_party_Library.
#Pip Install Name of the Three Modules.
!pip install numpy;
"""<! Starting of the Numpy Library and its's Functions & Operations.>"""
#Now, Importing the Numpy & then perform all functions and it's operatiosns.
import numpy as np
V=np.array([1,2,3,4,5]);
D=[1,2,3,4,5];
print("\n Values of ",V," and type of item it Contains: ",type(V));
print("\n Values of ",D," and type of item it Contains: ",type(D));
#checking the Dimensions of the Array.
#NOTE: In, Python Numpy we used to call Dimensions as an axes!
import numpy as np;
check=np.array([[1,2] , [3,4] , [5,6], [7,8]]);
print("\n Dimensions of the Array: ",check.ndim);
#Calculating the Total Size of an Array!
#NOTE: Both, shape() & size() is similar to find the total length of item in any dimension of numpy array!
import numpy as np;
checking=np.array([[[1,2,3,4], [4,5,6,7], [6,7,8,9], [3,44,56,100]]]);
#Checking the Dimensions of the Matrix.
print("\n 1. Dimension of the Matrix is: ",checking.ndim);
print("\n 3. Size of the Matrix are: ",checking.size);
print("\n 2. Total Axes of the Matrix are: ",checking.shape);
#chekcing the functions like data, itemsize, dtype.
import numpy as np;
checking=np.array([[1,2,3,4], [4,5,6,7], [6,7,8,9], [3,44,56,100]]);
#Performing the Operations in the Matrix.
print("\n 1. Size of the Matrix: ",checking.shape);
print("\n 2. Item-Size in the matrix: ",checking.itemsize);
print("\n 3. Checking the Data-type of item presented in Matrix are: ",checking.dtype);
print("\n 4. Checking the Data-type of item presented in Matrix are: ",checking.dtype.itemsize);
#Arange() functions simply gives you the initial-ending point values within the Ranges.
import numpy as np;
a=np.arange(10);
print("\n Values: ",a);
#Some Functions based on Arange() Functions.
import numpy as np;
aa=np.arange(1,10,2); #(START | END | STEP-SIZE)!
print("\n The Values of aa: ",aa);
#We, will also using floating points values within the Arange Functions.
b=np.arange(1,10,0.5); #(START | END | STEP-SIZE)!
print("\n Hence, Values of b: ",b);
#Total Size of the Array will be Calculated!
c=np.arange(1,10,0.2); #(START | END | STEP-SIZE)!
print("\n Values of c: ",c," and size is: ",c.size," Similar in terms with the shape(): ",c.shape);
#The type of the array can also be explicitly specified at creation time:
import numpy as np;
d=np.array([11,24.4,89.7,6.35], dtype="complex");
print("\n Values of the d: ",d);
c=np.array([45,56.9,8.1,23,34,5], dtype="float");
print("\n Vaues of c: ",c);
e=np.array([45.1,56.9,8.1,2.93,3.4,5.567], dtype="int");
print("\n Vaues of e: ",e);
#Putting all Zeros and ones in numpy array.
import numpy as np;
a=np.zeros(10);
print("\n Values are: ",a);
c=np.zeros((3,4));
print("\n Values of Matrix are: ",c);
#Putting Values in form of Ones.
b=np.ones((2,3,4));
print("\n Matrix: ",b);
e=np.ones((2,3), dtype="complex");
print("\n Complex-Matrix: ",e);
#Conversion of lst in the form of an Array!
import numpy as np;
p=np.array([1,23,4,5]);
q=[67,89,90,12,2,34];
#Convert(list-form into an array!);
r=np.array(q);
print("\n Values of r: ",r);
#Arange Functions is used to give data values within the range but not-precise & Accurate takes mre time in calculation for complex data-sets.
#The Linespace() function is used in place of arange() values.
# linespace() gives correct & accurate results data-sets.
import numpy as np;
a=np.linspace(1,10,9);
print("\n Values of a: ",a);
print("\n Total Size of data from linespace are: ",a.size);
#Printing of an Arrays.
a=np.arange(15);
print("\n 1. Arrange Values: ",a);
b=np.arange(1,10,0.5); #(START | END | STEP-SIZE);
print("\n 2. Values of b: ",b);
c=np.array([[12,23,34,54],[34,44,56,67]], dtype="complex");
print("\n 3. Array of c: ",c);
d=np.arange(12).reshape(3,4);
print("\n 4. Reshaping of d: ",d);
e=np.arange(24).reshape(2,3,4);
print("\n 5. Reshaping values of e: ",e);
#NOTE: If, the Values too much greater then numpy automatically skips the central data and show only corners-Values.
a=np.arange(10000);
print("\n Values of a: ",a); #Larger Values it skip central data without showing corner-data has been visible.
b=np.arange(100).reshape(10,10);
print("\n Values of b: ",b); #All Value visible without skip because data-set avilable in smaller-size.
#Basic Operations In Numpy.
#Random Values Generations.
import numpy as np
a=np.random.random((2,3));
print("\n Values of a: ",a);
#After, every execution it can generates random values.
#We, will talk about 'seed()' part of the random functions.
b=np.random.seed((1,50,2));
print("\n Values of b: ",b);
#generating random values and then finding the values like: max() & min().
import numpy as np;
e=np.random.random((2,3));
print("\n",e);
print("\n Maximum Values: ",e.max());
print("\n Minimum Values: ",e.min());
print("\n Total Sum is: ",e.sum());
#Random Integer Number Generations.
import numpy as np;
no1=np.random.randint(10,50,size=(50));
print("\n Values of no1: ",no1);
print("\n Total Size of an Arrany: ",no1.size);
#Generating Random Integer Numbers.
# few more numpy functions
d = np.zeros((10))
print(d)
r = np.ones((10))*2
print(r)
g = np.full((10),100)
print(g)
# statistical function
np.random.seed(10)
var2 = np.random.randint(10,100,(50))
s = var2.sum()
t = var2.min()
m = var2.max()
max_ind = var2.argmax()
min_ind = var2.argmin()
avg = var2.mean()
print(var2)
print()
print("min: ",t,'Pos:',min_ind)
print("max: ",m,'Pos:',max_ind)
print("average: ",avg)
print("sum of all the elements: ",s )
#Userlibraries and custom libraries as well!
import matplotlib.pyplot as plt;
import numpy as np;
X=np.linspace(1,20,100);
Y=np.sin(X);
Z=np.cos(X);
W=2*np.sin(X)+np.cos(X);
P=np.sin(2*X)-2*np.cos(X);
plt.figure(1,figsize=(5,2));
plt.plot(X,Y,'r',linewidth='4');
plt.title("Clock-Pendulum Motion!");
plt.xlabel("Sin-Functions");
plt.ylabel("Cos-Functions");
plt.grid("on");
import matplotlib.pyplot as plt;
import numpy as np;
#We, takes the Values of the Data-sets Conditions.
X=np.linspace(1,20,100);
Y=np.sin(X);
Z=np.cos(X);
W=2*np.sin(X)+np.cos(X);
P=np.sin(2*X)-2*np.cos(X);
plt.figure(1,figsize=(5,2));
plt.plot(X,Y,'m',linewidth='4');
plt.title("Moving Speed of the Car (Graphical - Form)");
plt.xlabel("Time");
plt.ylabel("Speed");
plt.grid("on");
#Another Graphical Manner!
plt.figure(1,figsize=(5,2));
plt.plot(X,Z,'c',linewidth='4');
plt.title("Moving Speed of the Car (Graphical - Form)");
plt.xlabel("Time");
plt.ylabel("Speed");
plt.grid("on");
#3rd Graphical Forms!
plt.figure(1,figsize=(5,2));
plt.plot(X,P,'r',linewidth='4');
plt.title("Moving Speed of the Car (Graphical - Form)");
plt.xlabel("Time");
plt.ylabel("Speed");
plt.grid("on");
#4th Graphical Forms!
plt.figure(1,figsize=(5,2));
plt.plot(X,W,'b',linewidth='4');
plt.title("Moving Speed of the Car (Graphical - Form)");
plt.xlabel("Time");
plt.ylabel("Speed");
plt.grid("on");
#5th Graphical Forms!
plt.figure(1,figsize=(5,2));
plt.plot(X,Y,'d',linewidth='4');
plt.title("Moving Speed of the Car (Graphical - Form)");
plt.xlabel("Time");
plt.ylabel("Speed");
plt.legend();
plt.grid("on");
#Generate a Graph with (Acceleration - Velocity Time Graph!).
import matplotlib.pyplot as plt;
import numpy as np;
#Putting & Generating the Values of the Data.
X=np.linspace(1,50,100);
Y=np.sin(X);
Z=np.cos(X);
W=2*np.sin(X)+np.cos(X);
P=np.sin(2*X)-2*np.cos(X);
#Designing the Figure suitable for the Human-Interface!
plt.figure(1,figsize=(10,4),label="Sin(X)");
plt.plot(X,Y,"r",linewidth='4',label="Sin(X)");
plt.plot(X,Z,"b",linewidth='4',label="Cos(X)");
plt.plot(X,W,"g",linewidth='4',label="Func1(X)");
plt.plot(X,P,"m",linewidth='4',label="Func2(X)");
#Finalizing & Designing , Mentioning the Details related to the Graph!
plt.title("Velocity/Acceleraation (Time-Graph)");
plt.xlabel("Velocity");
plt.ylabel("Acceleration");
plt.legend();
plt.grid("on");