Implementation of Machine Learning at Hackveda

Devanshu Shukla
Sep 2, 2018 · 2 min read

NumPy Implementation

NumPy is a library used in Python Programming Language adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.

Pre-Requisites

Basic Knowledge about python.

We will learn about:
1. Identity
2. Astype
3. Arange
4. Linspace
5. Indices
6. Data types
7. Reshape Function
8. Converting List into an Array
9. Slicing

Identity

importing NumPy Library

Identity is used in Python to create the identity matrix. Identity matrix is a square matrix in which all the elements of the principal diagonal are ones and all other elements are zeros. The effect of multiplying a given matrix by an identity matrix is to leave the given matrix unchanged.
so the code is as shown below.

identity matrix of 3

in this the number inside the identity function gives the size of identity matrix. the data type of this matrix is float.

Astype

Astype is used to change the data type in python programming language.
so for above example we will convert all the values into int data type.

astype is used to change the data type

so the data type of identity is now changed into integer data type.

Arange

Arange is used to return an array with evenly spaced elements as per the interval.
arange([start,] stop[, step,][, dtype])
Parameters:
start : [optional] start of interval range. By default start = 0
stop : end of interval range
step : [optional] step size of interval. By default step size = 1,
For any output out, this is the distance between two adjacent values, out[i+1] — out[i].
dtype : type of output array

different types to use Arange

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade