SlideShare a Scribd company logo
Talk: Hack Linear Algebra with Python for Deep Neural Network
Speaker: Chetan Khatri, Department of Computer Science, University of
Kachchh alumnus.
Lead - Technology, Accionlabs Inc.
In [1]:
from IPython.display import Image
In [2]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-24-40.png")
In [3]:
Image(filename="/home/chetan/Downloads/screenshot-towardsdatascience.com-2018-01
-13-07-49-05-835.png")
common linear algebra operations used in Neural Network
Out[2]:
Out[3]:
Say What ? Linear Algebra for Neural Network
In the context of deep learning / Neural network, linear algebra is a mathematical toolbox that offers helpful
techniques for manipulating groups of numbers simultaneously. It provides structures like vectors and
matrices (spreadsheets) to hold these numbers and new rules for how to add, subtract, multiply, and divide
them.
Why is it useful?
It turns complicated problems into simple, intuitive, efficiently calculated problems. Here is an example of
how linear algebra can achieve greater speed and simplicity.
In [4]:
import numpy as np
In [5]:
# Multiply two arrays
x = [1,2,3]
y = [2,3,4]
product = []
for i in range(len(x)):
product.append(x[i]*y[i])
print product
In [6]:
# Linear algebra version
x = np.array([1,2,3])
y = np.array([2,3,4])
x * y
After initializing the arrays, the linear algebra approach was 3x faster.
How is it used in Artificial Neural Network / deep learning ?
Neural networks store weights in matrices. Linear algebra makes matrix operations fast and easy, especially
when training on GPUs. In fact, GPUs were created with vector and matrix operations in mind. Similar to how
images can be represented as arrays of pixels, video games generate compelling gaming experiences using
enormous, constantly evolving matrices. Instead of processing pixels one-by-one, GPUs manipulate entire
matrices of pixels in parallel.
Vectors
[2, 6, 12]
Out[6]:
array([ 2, 6, 12])
Vectors are 1-dimensional arrays of numbers or terms. In geometry, vectors store the magnitude and
direction of a potential change to a point. The vector [3, -2] says go right 3 and down 2. A vector with more
than one dimension is called a matrix.
Vector -> is arrow pointing in a space. What defines a vector: length and direction it's pointing, as long as
length and direction are same you can move all around.
Vectors in geometry
In [7]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-36-32.png")
Out[7]:
In [8]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-36-36.png")
In [9]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-36-42.png")
Out[8]:
Out[9]:
In [10]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-39-55.png")
In [11]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-39-53.png")
Vector lives in flat plane is 2 dimensional.
Out[10]:
Out[11]:
In [12]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-41-09.png")
If vector sits in broader space where you and I leave they are 3 Dimensional.
In [13]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-46-00.png")
vector addition & vector multiplication plays important role in linear algebra
positive numbers indicating rightward and upward motion negative numbers indicating leftward and
downward motion
Out[12]:
Out[13]:
Every pair of number gives 1 and only 1 vector. And every vector is associated with 1 and only 1 pair of
number.
3 Dimensions - Z
Z - Parpendicular to both X & Y axis, which orders triplet numbers.
[2 1 3] Move along to how far to X axis. How far to move parellel to Y axis. How far to move parellel to Z axis
In Brief: Vectors typically represent movement from a point. They store both the magnitude and direction of
potential changes to a point. The vector [-2,5] says move left 2 units and up 5 units.
A vector can be applied to any point in space. The vector’s direction equals the slope of the hypotenuse
created moving up 5 and left 2. Its magnitude equals the length of the hypotenuse.
What's going on to space & Ask computer to figure it out numerically.
Scalar operations
Scalar operations involve a vector and a number. You modify the vector in-place by adding, subtracting, or
multiplying the number from all the values in the vector.
Examples: Streaching vector by scalar, Scaling Vector by scalar, Squash in vector by Scalar, Shear vector in
plane geometry
In [14]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-51-02.png")
Out[14]:
In [15]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-30.png")
In [16]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-33.png")
Out[15]:
Out[16]:
In [17]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-40.png")
In [18]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-41.png")
Out[17]:
Out[18]:
In [19]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-53-00.png")
In [20]:
Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-53-17.png")
Span: What does the span of two 3d vectors look like ?
All possible linear combination of two vectors. If one vector is already span of other then it's called "Linearly
dependent" for some values of a and b. Each vector adds another dimension to span that's "Linearly
independent" w /= av for all values of a.
Out[19]:
Out[20]:
Basis The basis of a vector space is a set of linearly independent vectors that span the full space. The word
"transformation" suggests that you think using "Movement"
Transformation is linear: If all lines must remain lines, origin remains fixed. Not linear: Some lines get
curved, grid lines remain parellel and evenly spaced.
Elementwise operations
In [21]:
Image(filename="/home/chetan/Music/images/1_g7cc0GkA7xrkhoh-__Ok3g.png")
In elementwise operations like addition, subtraction, and division, values that correspond positionally are
combined to produce a new vector. The 1st value in vector A is paired with the 1st value in vector B. The 2nd
value is paired with the 2nd, and so on. This means the vectors must have equal dimensions to complete the
operation.*
In [22]:
Image(filename="/home/chetan/Music/images/2.png")
In [23]:
y = np.array([1,2,3])
x = np.array([2,3,4])
In [24]:
y + x
Out[21]:
Out[22]:
Out[24]:
array([3, 5, 7])
In [25]:
y - x
In [26]:
y / x
Vector multiplication
There are two types of vector multiplication: Dot product and Hadamard product.
Dot product
The dot product of two vectors is a scalar. Dot product of vectors and matrices (matrix multiplication) is one of
the most important operations in deep learning.
In [27]:
Image(filename="/home/chetan/Music/images/3.png")
In [28]:
y = np.array([1,2,3])
x = np.array([2,3,4])
In [29]:
np.dot(y,x)
Hadamard product
Hadamard Product is elementwise multiplication and it outputs a vector.
Out[25]:
array([-1, -1, -1])
Out[26]:
array([0, 0, 0])
Out[27]:
Out[29]:
20
In [30]:
Image(filename="/home/chetan/Music/images/4.png")
In [31]:
y = np.array([1,2,3])
x = np.array([2,3,4])
In [32]:
y * x
Vector fields
A vector field shows how far the point (x,y) would hypothetically move if we applied a vector function to it like
addition or multiplication. Given a point in space, a vector field shows the power and direction of our
proposed change at a variety of points in a graph.
In [33]:
Image(filename="/home/chetan/Music/images/5.png")
Matrices
A matrix is a rectangular grid of numbers or terms (like an Excel spreadsheet) with special rules for addition,
subtraction, and multiplication.
Out[30]:
Out[32]:
array([ 2, 6, 12])
Out[33]:
Matrix dimensions
We describe the dimensions of a matrix in terms of rows by columns.
In [34]:
Image(filename="/home/chetan/Music/images/6.png")
In [35]:
a = np.array([
[1,2,3],
[4,5,6]
])
In [36]:
a.shape
In [37]:
b = np.array([
[1,2,3]
])
In [38]:
b.shape
Matrix scalar operations
Scalar operations with matrices work the same way as they do for vectors. Simply apply the scalar to every
element in the matrix—add, subtract, divide, multiply, etc.
Out[34]:
Out[36]:
(2, 3)
Out[38]:
(1, 3)
In [39]:
Image(filename="/home/chetan/Music/images/7.png")
In [40]:
a = np.array(
[[1,2],
[3,4]])
In [41]:
a + 1
Matrix elementwise operations
In order to add, subtract, or divide two matrices they must have equal dimensions.* We combine
corresponding values in an elementwise fashion to produce a new matrix.
In [42]:
Image(filename="/home/chetan/Music/images/8.png")
In [43]:
a = np.array([
[1,2],
[3,4]
])
b = np.array([
[1,2],
[3,4]
])
Out[39]:
Out[41]:
array([[2, 3],
[4, 5]])
Out[42]:
In [44]:
a + b
In [45]:
a - b
Numpy broadcasting*
In numpy the dimension requirements for elementwise operations are relaxed via a mechanism called
broadcasting. Two matrices are compatible if the corresponding dimensions in each matrix (rows vs rows,
columns vs columns) meet the following requirements:
1. The dimensions are equal, or
2. One dimension is of size 1
In [46]:
a = np.array([
[1],
[2]
])
b = np.array([
[3,4],
[5,6]
])
c = np.array([
[1,2]
])
In [47]:
# Same no. of rows
# Different no. of columns
# but a has one column so this works
a * b
Out[44]:
array([[2, 4],
[6, 8]])
Out[45]:
array([[0, 0],
[0, 0]])
Out[47]:
array([[ 3, 4],
[10, 12]])
In [48]:
# Same no. of columns
# Different no. of rows
# but c has one row so this works
b * c
In [49]:
# Different no. of columns
# Different no. of rows
# but both a and c meet the
# size 1 requirement rule
a + c
Things get weirder in higher dimensions—3D, 4D, but for now we won’t worry about that. Understanding 2D
operations is a good start.
Matrix Hadamard product
Hadamard product of matrices is an elementwise operation. Values that correspond positionally are
multiplied to produce a new matrix.
In [50]:
Image(filename="/home/chetan/Music/images/9.png")
Out[48]:
array([[ 3, 8],
[ 5, 12]])
Out[49]:
array([[2, 3],
[3, 4]])
Out[50]:
In [51]:
a = np.array(
[[2,3],
[2,3]])
b = np.array(
[[3,4],
[5,6]])
# Uses python's multiply operator
a * b
In numpy you can take the Hadamard product of a matrix and vector as long as their dimensions meet the
requirements of broadcasting.
In [52]:
Image(filename="/home/chetan/Music/images/10.png")
Matrix transpose
Neural networks frequently process weights and inputs of different sizes where the dimensions do not meet
the requirements of matrix multiplication. Matrix transpose provides a way to “rotate” one of the matrices so
that the operation complies with multiplication requirements and can continue. There are two steps to
transpose a matrix: Rotate the matrix right 90° Reverse the order of elements in each row (e.g. [a b c]
becomes [c b a]) As an example, transpose matrix M into T:
Out[51]:
array([[ 6, 12],
[10, 18]])
Out[52]:
In [53]:
Image(filename="/home/chetan/Music/images/11.png")
In [54]:
a = np.array([
[1, 2],
[3, 4]])
a.T
Matrix multiplication
Matrix multiplication specifies a set of rules for multiplying matrices together to produce a new matrix.
Rules
Not all matrices are eligible for multiplication. In addition, there is a requirement on the dimensions of the
resulting matrix output.
1. The number of columns of the 1st matrix must equal the number of rows of the 2nd
2. The product of an M x N matrix and an N x K matrix is an M x K matrix. The new matrix takes the
rows of the 1st and columns of the 2nd
Steps
Matrix multiplication relies on dot product to multiply various combinations of rows and columns.
Out[53]:
Out[54]:
array([[1, 3],
[2, 4]])
In [57]:
Image(filename="/home/chetan/Music/images/12.png")
The operation a1 · b1 means we take the dot product of the 1st row in matrix A (1, 7) and the 1st column in
matrix B (3, 5).
In [58]:
Image(filename="/home/chetan/Music/images/13.png")
Here’s another way to look at it:
In [59]:
Image(filename="/home/chetan/Music/images/14.png")
Test yourself with these examples
Out[57]:
Out[58]:
Out[59]:
Ad

More Related Content

What's hot (17)

Computer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientComputer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and Gradient
Ahmed Gad
 
Fuzzy c means manual work
Fuzzy c means manual workFuzzy c means manual work
Fuzzy c means manual work
Dr.E.N.Sathishkumar
 
PCA and SVD in brief
PCA and SVD in briefPCA and SVD in brief
PCA and SVD in brief
N. I. Md. Ashafuddula
 
K means clustering
K means clusteringK means clustering
K means clustering
keshav goyal
 
A Correlative Information-Theoretic Measure for Image Similarity
A Correlative Information-Theoretic Measure for Image SimilarityA Correlative Information-Theoretic Measure for Image Similarity
A Correlative Information-Theoretic Measure for Image Similarity
Farah M. Altufaili
 
Principal component analysis
Principal component analysisPrincipal component analysis
Principal component analysis
Farah M. Altufaili
 
Lda
LdaLda
Lda
sk19920909
 
Pca ankita dubey
Pca ankita dubeyPca ankita dubey
Pca ankita dubey
Ankita Dubey
 
Log polar coordinates
Log polar coordinatesLog polar coordinates
Log polar coordinates
Oğul Göçmen
 
Image recogonization
Image recogonizationImage recogonization
Image recogonization
SANTOSH RATH
 
digital image processing, image processing
digital image processing, image processingdigital image processing, image processing
digital image processing, image processing
Kalyan Acharjya
 
Visualizing the Model Selection Process
Visualizing the Model Selection ProcessVisualizing the Model Selection Process
Visualizing the Model Selection Process
Benjamin Bengfort
 
Wordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing ProjectWordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing Project
Surya Chandra
 
07 dimensionality reduction
07 dimensionality reduction07 dimensionality reduction
07 dimensionality reduction
Marco Quartulli
 
Understandig PCA and LDA
Understandig PCA and LDAUnderstandig PCA and LDA
Understandig PCA and LDA
Dr. Syed Hassan Amin
 
Dimensionality reduction
Dimensionality reductionDimensionality reduction
Dimensionality reduction
Shatakirti Er
 
Design and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation AlgorithmsDesign and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation Algorithms
Ajay Bidyarthy
 
Computer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientComputer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and Gradient
Ahmed Gad
 
K means clustering
K means clusteringK means clustering
K means clustering
keshav goyal
 
A Correlative Information-Theoretic Measure for Image Similarity
A Correlative Information-Theoretic Measure for Image SimilarityA Correlative Information-Theoretic Measure for Image Similarity
A Correlative Information-Theoretic Measure for Image Similarity
Farah M. Altufaili
 
Image recogonization
Image recogonizationImage recogonization
Image recogonization
SANTOSH RATH
 
digital image processing, image processing
digital image processing, image processingdigital image processing, image processing
digital image processing, image processing
Kalyan Acharjya
 
Visualizing the Model Selection Process
Visualizing the Model Selection ProcessVisualizing the Model Selection Process
Visualizing the Model Selection Process
Benjamin Bengfort
 
Wordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing ProjectWordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing Project
Surya Chandra
 
07 dimensionality reduction
07 dimensionality reduction07 dimensionality reduction
07 dimensionality reduction
Marco Quartulli
 
Dimensionality reduction
Dimensionality reductionDimensionality reduction
Dimensionality reduction
Shatakirti Er
 
Design and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation AlgorithmsDesign and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation Algorithms
Ajay Bidyarthy
 

Similar to An Introduction Linear Algebra for Neural Networks and Deep learning (20)

vector application
vector applicationvector application
vector application
rajat shukla
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
UmarMustafa13
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
Diksha Trivedi
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
PremanandS3
 
Vectors.pptx
Vectors.pptxVectors.pptx
Vectors.pptx
NivethithaM9
 
Metric-learn, a Scikit-learn compatible package
Metric-learn, a Scikit-learn compatible packageMetric-learn, a Scikit-learn compatible package
Metric-learn, a Scikit-learn compatible package
William de Vazelhes
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_r
Razzaqe
 
Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...
Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...
Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...
ZaidHussein6
 
8. Vectors data frames
8. Vectors data frames8. Vectors data frames
8. Vectors data frames
ExternalEvents
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
Make Mannan
 
SessionFour_DataTypesandObjects
SessionFour_DataTypesandObjectsSessionFour_DataTypesandObjects
SessionFour_DataTypesandObjects
Hellen Gakuruh
 
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in TheanoConvolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Seongwon Hwang
 
Deep Residual Hashing Neural Network for Image Retrieval
Deep Residual Hashing Neural Network for Image RetrievalDeep Residual Hashing Neural Network for Image Retrieval
Deep Residual Hashing Neural Network for Image Retrieval
Edwin Efraín Jiménez Lepe
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
Lakshmi Sarvani Videla
 
Basics of Digital Images
Basics of  Digital ImagesBasics of  Digital Images
Basics of Digital Images
Saad Al-Momen
 
Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...
Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...
Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...
CSCJournals
 
FORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHOD
FORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHODFORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHOD
FORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHOD
editorijcres
 
Report
ReportReport
Report
Vartika Sharma
 
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionSimple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Anish Patel
 
Solving linear equations from an image using ann
Solving linear equations from an image using annSolving linear equations from an image using ann
Solving linear equations from an image using ann
eSAT Journals
 
vector application
vector applicationvector application
vector application
rajat shukla
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
UmarMustafa13
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
PremanandS3
 
Metric-learn, a Scikit-learn compatible package
Metric-learn, a Scikit-learn compatible packageMetric-learn, a Scikit-learn compatible package
Metric-learn, a Scikit-learn compatible package
William de Vazelhes
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_r
Razzaqe
 
Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...
Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...
Stereo Vision Distance Estimation Employing Canny Edge Detector with Interpol...
ZaidHussein6
 
8. Vectors data frames
8. Vectors data frames8. Vectors data frames
8. Vectors data frames
ExternalEvents
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
Make Mannan
 
SessionFour_DataTypesandObjects
SessionFour_DataTypesandObjectsSessionFour_DataTypesandObjects
SessionFour_DataTypesandObjects
Hellen Gakuruh
 
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in TheanoConvolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Seongwon Hwang
 
Deep Residual Hashing Neural Network for Image Retrieval
Deep Residual Hashing Neural Network for Image RetrievalDeep Residual Hashing Neural Network for Image Retrieval
Deep Residual Hashing Neural Network for Image Retrieval
Edwin Efraín Jiménez Lepe
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
Lakshmi Sarvani Videla
 
Basics of Digital Images
Basics of  Digital ImagesBasics of  Digital Images
Basics of Digital Images
Saad Al-Momen
 
Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...
Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...
Performance Comparison of Image Retrieval Using Fractional Coefficients of Tr...
CSCJournals
 
FORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHOD
FORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHODFORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHOD
FORGERY (COPY-MOVE) DETECTION IN DIGITAL IMAGES USING BLOCK METHOD
editorijcres
 
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionSimple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Anish Patel
 
Solving linear equations from an image using ann
Solving linear equations from an image using annSolving linear equations from an image using ann
Solving linear equations from an image using ann
eSAT Journals
 
Ad

More from Chetan Khatri (20)

Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...
Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...
Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...
Chetan Khatri
 
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Chetan Khatri
 
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-AirflowPyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
Chetan Khatri
 
ScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in productionScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in production
Chetan Khatri
 
No more struggles with Apache Spark workloads in production
No more struggles with Apache Spark workloads in productionNo more struggles with Apache Spark workloads in production
No more struggles with Apache Spark workloads in production
Chetan Khatri
 
PyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_production
PyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_productionPyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_production
PyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_production
Chetan Khatri
 
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaAutomate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Chetan Khatri
 
HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...
HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...
HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...
Chetan Khatri
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
Chetan Khatri
 
An Introduction to Spark with Scala
An Introduction to Spark with ScalaAn Introduction to Spark with Scala
An Introduction to Spark with Scala
Chetan Khatri
 
HBase with Apache Spark POC Demo
HBase with Apache Spark POC DemoHBase with Apache Spark POC Demo
HBase with Apache Spark POC Demo
Chetan Khatri
 
HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...
HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...
HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...
Chetan Khatri
 
HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...
HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...
HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...
Chetan Khatri
 
Fossasia 2018-chetan-khatri
Fossasia 2018-chetan-khatriFossasia 2018-chetan-khatri
Fossasia 2018-chetan-khatri
Chetan Khatri
 
Fossasia ai-ml technologies and application for product development-chetan kh...
Fossasia ai-ml technologies and application for product development-chetan kh...Fossasia ai-ml technologies and application for product development-chetan kh...
Fossasia ai-ml technologies and application for product development-chetan kh...
Chetan Khatri
 
Introduction to Computer Science
Introduction to Computer ScienceIntroduction to Computer Science
Introduction to Computer Science
Chetan Khatri
 
An introduction to Git with Atlassian Suite
An introduction to Git with Atlassian SuiteAn introduction to Git with Atlassian Suite
An introduction to Git with Atlassian Suite
Chetan Khatri
 
Think machine-learning-with-scikit-learn-chetan
Think machine-learning-with-scikit-learn-chetanThink machine-learning-with-scikit-learn-chetan
Think machine-learning-with-scikit-learn-chetan
Chetan Khatri
 
A step towards machine learning at accionlabs
A step towards machine learning at accionlabsA step towards machine learning at accionlabs
A step towards machine learning at accionlabs
Chetan Khatri
 
Voltage measurement using arduino
Voltage measurement using arduinoVoltage measurement using arduino
Voltage measurement using arduino
Chetan Khatri
 
Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...
Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...
Data Science for Beginner by Chetan Khatri and Deptt. of Computer Science, Ka...
Chetan Khatri
 
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Chetan Khatri
 
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-AirflowPyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
Chetan Khatri
 
ScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in productionScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in production
Chetan Khatri
 
No more struggles with Apache Spark workloads in production
No more struggles with Apache Spark workloads in productionNo more struggles with Apache Spark workloads in production
No more struggles with Apache Spark workloads in production
Chetan Khatri
 
PyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_production
PyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_productionPyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_production
PyConLT19-No_more_struggles_with_Apache_Spark_(PySpark)_workloads_in_production
Chetan Khatri
 
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaAutomate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Chetan Khatri
 
HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...
HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...
HBaseConAsia 2018 - Scaling 30 TB's of Data lake with Apache HBase and Scala ...
Chetan Khatri
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
Chetan Khatri
 
An Introduction to Spark with Scala
An Introduction to Spark with ScalaAn Introduction to Spark with Scala
An Introduction to Spark with Scala
Chetan Khatri
 
HBase with Apache Spark POC Demo
HBase with Apache Spark POC DemoHBase with Apache Spark POC Demo
HBase with Apache Spark POC Demo
Chetan Khatri
 
HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...
HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...
HKOSCon18 - Chetan Khatri - Open Source AI / ML Technologies and Application ...
Chetan Khatri
 
HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...
HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...
HKOSCon18 - Chetan Khatri - Scaling TB's of Data with Apache Spark and Scala ...
Chetan Khatri
 
Fossasia 2018-chetan-khatri
Fossasia 2018-chetan-khatriFossasia 2018-chetan-khatri
Fossasia 2018-chetan-khatri
Chetan Khatri
 
Fossasia ai-ml technologies and application for product development-chetan kh...
Fossasia ai-ml technologies and application for product development-chetan kh...Fossasia ai-ml technologies and application for product development-chetan kh...
Fossasia ai-ml technologies and application for product development-chetan kh...
Chetan Khatri
 
Introduction to Computer Science
Introduction to Computer ScienceIntroduction to Computer Science
Introduction to Computer Science
Chetan Khatri
 
An introduction to Git with Atlassian Suite
An introduction to Git with Atlassian SuiteAn introduction to Git with Atlassian Suite
An introduction to Git with Atlassian Suite
Chetan Khatri
 
Think machine-learning-with-scikit-learn-chetan
Think machine-learning-with-scikit-learn-chetanThink machine-learning-with-scikit-learn-chetan
Think machine-learning-with-scikit-learn-chetan
Chetan Khatri
 
A step towards machine learning at accionlabs
A step towards machine learning at accionlabsA step towards machine learning at accionlabs
A step towards machine learning at accionlabs
Chetan Khatri
 
Voltage measurement using arduino
Voltage measurement using arduinoVoltage measurement using arduino
Voltage measurement using arduino
Chetan Khatri
 
Ad

Recently uploaded (20)

Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
Guru Nanak Technical Institutions
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
Working with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to ImplementationWorking with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to Implementation
Alabama Transportation Assistance Program
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 

An Introduction Linear Algebra for Neural Networks and Deep learning

  • 1. Talk: Hack Linear Algebra with Python for Deep Neural Network Speaker: Chetan Khatri, Department of Computer Science, University of Kachchh alumnus. Lead - Technology, Accionlabs Inc. In [1]: from IPython.display import Image In [2]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-24-40.png") In [3]: Image(filename="/home/chetan/Downloads/screenshot-towardsdatascience.com-2018-01 -13-07-49-05-835.png") common linear algebra operations used in Neural Network Out[2]: Out[3]:
  • 2. Say What ? Linear Algebra for Neural Network In the context of deep learning / Neural network, linear algebra is a mathematical toolbox that offers helpful techniques for manipulating groups of numbers simultaneously. It provides structures like vectors and matrices (spreadsheets) to hold these numbers and new rules for how to add, subtract, multiply, and divide them. Why is it useful? It turns complicated problems into simple, intuitive, efficiently calculated problems. Here is an example of how linear algebra can achieve greater speed and simplicity. In [4]: import numpy as np In [5]: # Multiply two arrays x = [1,2,3] y = [2,3,4] product = [] for i in range(len(x)): product.append(x[i]*y[i]) print product In [6]: # Linear algebra version x = np.array([1,2,3]) y = np.array([2,3,4]) x * y After initializing the arrays, the linear algebra approach was 3x faster. How is it used in Artificial Neural Network / deep learning ? Neural networks store weights in matrices. Linear algebra makes matrix operations fast and easy, especially when training on GPUs. In fact, GPUs were created with vector and matrix operations in mind. Similar to how images can be represented as arrays of pixels, video games generate compelling gaming experiences using enormous, constantly evolving matrices. Instead of processing pixels one-by-one, GPUs manipulate entire matrices of pixels in parallel. Vectors [2, 6, 12] Out[6]: array([ 2, 6, 12])
  • 3. Vectors are 1-dimensional arrays of numbers or terms. In geometry, vectors store the magnitude and direction of a potential change to a point. The vector [3, -2] says go right 3 and down 2. A vector with more than one dimension is called a matrix. Vector -> is arrow pointing in a space. What defines a vector: length and direction it's pointing, as long as length and direction are same you can move all around. Vectors in geometry In [7]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-36-32.png") Out[7]:
  • 4. In [8]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-36-36.png") In [9]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-36-42.png") Out[8]: Out[9]:
  • 5. In [10]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 14-39-55.png") In [11]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-39-53.png") Vector lives in flat plane is 2 dimensional. Out[10]: Out[11]:
  • 6. In [12]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-41-09.png") If vector sits in broader space where you and I leave they are 3 Dimensional. In [13]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-46-00.png") vector addition & vector multiplication plays important role in linear algebra positive numbers indicating rightward and upward motion negative numbers indicating leftward and downward motion Out[12]: Out[13]:
  • 7. Every pair of number gives 1 and only 1 vector. And every vector is associated with 1 and only 1 pair of number. 3 Dimensions - Z Z - Parpendicular to both X & Y axis, which orders triplet numbers. [2 1 3] Move along to how far to X axis. How far to move parellel to Y axis. How far to move parellel to Z axis In Brief: Vectors typically represent movement from a point. They store both the magnitude and direction of potential changes to a point. The vector [-2,5] says move left 2 units and up 5 units. A vector can be applied to any point in space. The vector’s direction equals the slope of the hypotenuse created moving up 5 and left 2. Its magnitude equals the length of the hypotenuse. What's going on to space & Ask computer to figure it out numerically. Scalar operations Scalar operations involve a vector and a number. You modify the vector in-place by adding, subtracting, or multiplying the number from all the values in the vector. Examples: Streaching vector by scalar, Scaling Vector by scalar, Squash in vector by Scalar, Shear vector in plane geometry In [14]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-51-02.png") Out[14]:
  • 8. In [15]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-30.png") In [16]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-33.png") Out[15]: Out[16]:
  • 9. In [17]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-40.png") In [18]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-52-41.png") Out[17]: Out[18]:
  • 10. In [19]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-53-00.png") In [20]: Image(filename="/home/chetan/Pictures/Screenshot from 2018-01-12 15-53-17.png") Span: What does the span of two 3d vectors look like ? All possible linear combination of two vectors. If one vector is already span of other then it's called "Linearly dependent" for some values of a and b. Each vector adds another dimension to span that's "Linearly independent" w /= av for all values of a. Out[19]: Out[20]:
  • 11. Basis The basis of a vector space is a set of linearly independent vectors that span the full space. The word "transformation" suggests that you think using "Movement" Transformation is linear: If all lines must remain lines, origin remains fixed. Not linear: Some lines get curved, grid lines remain parellel and evenly spaced. Elementwise operations In [21]: Image(filename="/home/chetan/Music/images/1_g7cc0GkA7xrkhoh-__Ok3g.png") In elementwise operations like addition, subtraction, and division, values that correspond positionally are combined to produce a new vector. The 1st value in vector A is paired with the 1st value in vector B. The 2nd value is paired with the 2nd, and so on. This means the vectors must have equal dimensions to complete the operation.* In [22]: Image(filename="/home/chetan/Music/images/2.png") In [23]: y = np.array([1,2,3]) x = np.array([2,3,4]) In [24]: y + x Out[21]: Out[22]: Out[24]: array([3, 5, 7])
  • 12. In [25]: y - x In [26]: y / x Vector multiplication There are two types of vector multiplication: Dot product and Hadamard product. Dot product The dot product of two vectors is a scalar. Dot product of vectors and matrices (matrix multiplication) is one of the most important operations in deep learning. In [27]: Image(filename="/home/chetan/Music/images/3.png") In [28]: y = np.array([1,2,3]) x = np.array([2,3,4]) In [29]: np.dot(y,x) Hadamard product Hadamard Product is elementwise multiplication and it outputs a vector. Out[25]: array([-1, -1, -1]) Out[26]: array([0, 0, 0]) Out[27]: Out[29]: 20
  • 13. In [30]: Image(filename="/home/chetan/Music/images/4.png") In [31]: y = np.array([1,2,3]) x = np.array([2,3,4]) In [32]: y * x Vector fields A vector field shows how far the point (x,y) would hypothetically move if we applied a vector function to it like addition or multiplication. Given a point in space, a vector field shows the power and direction of our proposed change at a variety of points in a graph. In [33]: Image(filename="/home/chetan/Music/images/5.png") Matrices A matrix is a rectangular grid of numbers or terms (like an Excel spreadsheet) with special rules for addition, subtraction, and multiplication. Out[30]: Out[32]: array([ 2, 6, 12]) Out[33]:
  • 14. Matrix dimensions We describe the dimensions of a matrix in terms of rows by columns. In [34]: Image(filename="/home/chetan/Music/images/6.png") In [35]: a = np.array([ [1,2,3], [4,5,6] ]) In [36]: a.shape In [37]: b = np.array([ [1,2,3] ]) In [38]: b.shape Matrix scalar operations Scalar operations with matrices work the same way as they do for vectors. Simply apply the scalar to every element in the matrix—add, subtract, divide, multiply, etc. Out[34]: Out[36]: (2, 3) Out[38]: (1, 3)
  • 15. In [39]: Image(filename="/home/chetan/Music/images/7.png") In [40]: a = np.array( [[1,2], [3,4]]) In [41]: a + 1 Matrix elementwise operations In order to add, subtract, or divide two matrices they must have equal dimensions.* We combine corresponding values in an elementwise fashion to produce a new matrix. In [42]: Image(filename="/home/chetan/Music/images/8.png") In [43]: a = np.array([ [1,2], [3,4] ]) b = np.array([ [1,2], [3,4] ]) Out[39]: Out[41]: array([[2, 3], [4, 5]]) Out[42]:
  • 16. In [44]: a + b In [45]: a - b Numpy broadcasting* In numpy the dimension requirements for elementwise operations are relaxed via a mechanism called broadcasting. Two matrices are compatible if the corresponding dimensions in each matrix (rows vs rows, columns vs columns) meet the following requirements: 1. The dimensions are equal, or 2. One dimension is of size 1 In [46]: a = np.array([ [1], [2] ]) b = np.array([ [3,4], [5,6] ]) c = np.array([ [1,2] ]) In [47]: # Same no. of rows # Different no. of columns # but a has one column so this works a * b Out[44]: array([[2, 4], [6, 8]]) Out[45]: array([[0, 0], [0, 0]]) Out[47]: array([[ 3, 4], [10, 12]])
  • 17. In [48]: # Same no. of columns # Different no. of rows # but c has one row so this works b * c In [49]: # Different no. of columns # Different no. of rows # but both a and c meet the # size 1 requirement rule a + c Things get weirder in higher dimensions—3D, 4D, but for now we won’t worry about that. Understanding 2D operations is a good start. Matrix Hadamard product Hadamard product of matrices is an elementwise operation. Values that correspond positionally are multiplied to produce a new matrix. In [50]: Image(filename="/home/chetan/Music/images/9.png") Out[48]: array([[ 3, 8], [ 5, 12]]) Out[49]: array([[2, 3], [3, 4]]) Out[50]:
  • 18. In [51]: a = np.array( [[2,3], [2,3]]) b = np.array( [[3,4], [5,6]]) # Uses python's multiply operator a * b In numpy you can take the Hadamard product of a matrix and vector as long as their dimensions meet the requirements of broadcasting. In [52]: Image(filename="/home/chetan/Music/images/10.png") Matrix transpose Neural networks frequently process weights and inputs of different sizes where the dimensions do not meet the requirements of matrix multiplication. Matrix transpose provides a way to “rotate” one of the matrices so that the operation complies with multiplication requirements and can continue. There are two steps to transpose a matrix: Rotate the matrix right 90° Reverse the order of elements in each row (e.g. [a b c] becomes [c b a]) As an example, transpose matrix M into T: Out[51]: array([[ 6, 12], [10, 18]]) Out[52]:
  • 19. In [53]: Image(filename="/home/chetan/Music/images/11.png") In [54]: a = np.array([ [1, 2], [3, 4]]) a.T Matrix multiplication Matrix multiplication specifies a set of rules for multiplying matrices together to produce a new matrix. Rules Not all matrices are eligible for multiplication. In addition, there is a requirement on the dimensions of the resulting matrix output. 1. The number of columns of the 1st matrix must equal the number of rows of the 2nd 2. The product of an M x N matrix and an N x K matrix is an M x K matrix. The new matrix takes the rows of the 1st and columns of the 2nd Steps Matrix multiplication relies on dot product to multiply various combinations of rows and columns. Out[53]: Out[54]: array([[1, 3], [2, 4]])
  • 20. In [57]: Image(filename="/home/chetan/Music/images/12.png") The operation a1 · b1 means we take the dot product of the 1st row in matrix A (1, 7) and the 1st column in matrix B (3, 5). In [58]: Image(filename="/home/chetan/Music/images/13.png") Here’s another way to look at it: In [59]: Image(filename="/home/chetan/Music/images/14.png") Test yourself with these examples Out[57]: Out[58]: Out[59]:
  翻译: