EE453L Applied Machine Learning LAB 1
Understanding, Exploring and Installing the various
development environment for the Applied Machine
Learning Laboratory.
Learning Objectives
To get familiar with multiple online as well as localhost based IDE for executing
python programs
To install Anaconda and use Spyder IDE for coding
To recap the concept of coding learn in Programming Fundamental and Object
Oriented Programming
Learning Resources
[Link]
[Link]
[Link]
[Link]
Open Jupiter Notebook
EE453L Applied Machine Learning LAB 1
User account files
New folder to save python files
EE453L Applied Machine Learning LAB 1
Creation of python file within the folder, with extension ipynb
Renaming of the file can be done from the file from menu bar.
Jupiter file is ready to work for the lab.
What is the NumPy array?
EE453L Applied Machine Learning LAB 1
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.
To create a multidimensional array and perform a mathematical operation python NumPy
ndarray is the best choice. The ndarray stands for N-Dimensional arrays.
EE453L Applied Machine Learning LAB 1
Create NumPy ndarray (1D array)
Import of numpy
Numpy is successfully created
Create of 1 dimensional array using numpy
arr_1D = [Link]([2,4,6,8]) # create NumPy 1D array which contain int value 2,4,6,8
print(arr_1D) # print arr_1D
Creating a difference between array and list
type(arr_1D)
EE453L Applied Machine Learning LAB 1
Finding the dimension of the array
Create NumPy ndarray (2D array)
To create NumPy 2D array use array() function and give one argument of items of lists of the list
to it.
import numpy as np # import numpy package
arr_2D = [Link]([[0, 1, 1], [1, 0, 1], [1, 1, 0]]) # Create Numpy
2D array which contain inter type valye
print(arr_2D) # print arr_1D
You can find the size of the array
You can find the shape
You can find the data type
EE453L Applied Machine Learning LAB 1
Create NumPy ndarray (3D array)
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 = [Link]([[[0, 1, 1], [1, 0, 1], [1, 1, 0]]]) # create
numpy 3D array which contain integer values
print(arr_3D)
How to store different types of data in NumPy ndarray?
The array() function accepts different types of data. You can insert it while creating an array.
import numpy as np
# store student information in NumPy 2D array
student_info = [Link]([['id', 'name', 'marks'],
[101, 'Asad', 80],
[102, 'Asif', 75],
[103, 'Hassan',33],
[104, 'Abdullah',52]
])
EE453L Applied Machine Learning LAB 1
print(student_info)
How to set default data type?
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 = [Link]([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.
[Link]
[Link]
[Link]
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
• Write a code to slice this array to display the last column,
[[3] [6] [9]]
• Write a code to slice this array to display the last 2 elements of
middle array,
[5 6]