Machine Learning Lab 1
Machine Learning Lab 1
Learning Objectives
To get familiar with multiple online as well as localhost based IDE for executing
python programs
Learning Resources
https://anaconda.org/
https://docs.anaconda.com/anaconda/user-guide/getting-started/
https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/
https://colab.research.google.com/
Renaming of the file can be done from the file from menu bar.
Jupiter file is ready to work for the lab.
Python NumPy array is a collection of a homogeneous data type. It is most like the python list.
You can insert different types of data in it. Like integer, floating, list, tuple, string, etc.
Import of numpy
arr_1D = np.array([2,4,6,8]) # create NumPy 1D array which contain int value 2,4,6,8
To create NumPy 2D array use array() function and give one argument of items of lists of the list
to it.
To create NumPy 3D array use array() function and give one argument of items of lists of lists of
the list to it.
import numpy as np
arr_3D = np.array([[[0, 1, 1], [1, 0, 1], [1, 1, 0]]]) # create
numpy 3D array which contain integer values
print(arr_3D)
The array() function accepts different types of data. You can insert it while creating an array.
import numpy as np
[103, 'Hassan',33],
[104, 'Abdullah',52]
])
EE453L Applied Machine Learning LAB 1
print(student_info)
By default, The python NumPy array data type is none. To set it, give an argument to array()
function as the desired data type. like int, float, str, etc.
import numpy as np
percentage = np.array([80, 75, 33, 52], dtype = float) # set data
type as float
print(percentage)
Home Tasks/Exercises:
The submission deadline is before the next lab.
Task 1:
Creation of ndarrays and execute the following functions.
np.eye
np.arrange
np.random.randint
Print all results
Task 2:
Create ndarrays to perfom the following arithmetic functions.
Addition
Subtraction
Multiplication
Comparisons
Task 3:
Perform indexing and slicing by taking one dimensional array and print
each step.
Task 4:
• Consider the two-dimensional array, arr2d.
EE453L Applied Machine Learning LAB 1