You are on page 1of 6

Machine Learning 21BEC505

Experiment - 0
Lab Exercise:
Q1. Define a string ‘Hello World’ and store it in a variable ‘data’. Print the length of the string and access
the index of each letter.
Code:

Output:

Q2. Print the numbers from 0 to 9 in ascending order using for loop and while loop. Write an additional
code to print the number if it is less than 7.
Code:

Output:
Machine Learning 21BEC505

Q3. Declare a variable ‘userlist’ that lists arbitrary four data samples. Append any two data samples along
with the data of ‘userlist’ and print each element using for-loop.
Code:

Output:

Q4. Define two- and three-dimensional arrays with random values. Determine the dimensions, shape, and
size of those arrays. State the key difference among dimensions, shape, and size.
Code:

Output:
Machine Learning 21BEC505

Q5. For a generated random 3x3 matrix, find its rotated matrices with and without using for-loops. See
that you can convert the final matrix as a row or a column vector.
Code:

Output:

Q6. Generate two arbitrary 3x3 matrices, concatenate them along rows or columns and visualize. Also,
show the way to concatenate two matrices with unequal (but matched with row/col) dimensions.
Code:
Machine Learning 21BEC505

Output:

Q7. Generate x-y plots in python and show plots for sine and real exponentials in two separate plots. Try to
explore scatter plots and bar graphs to visualize the data.
Code:

Output:
Machine Learning 21BEC505

Q8. Create a dataframe that lists the batch-wise count of students for their choice among three electives.
Write a python code to access that count and add sum of all rows and columns.
Code:

Output:

Q9. Import following file formats and show how you can read them in Python.
● Comma-separated values
● XLSX
● Plain Text (txt)
● JSON
● XML
● HTML
● Images
● Hierarchical Data Format
● PDF
● DOCX
Machine Learning 21BEC505

Code:

Output:

Conclusion: In this experiment, basic python functions, data types like lists, dictionary, tuples, sets, looping
statements, if…else statements has been learnt. Also some libraries like numpy, pandas, matplotlib,
seaborn, scipy, sckitlearn, tensorflow, etc.. has been learnt.

You might also like