Update: This has been replaced with the following Jupyter notebook:
https://github.com/JeffBohn/notebooks/blob/master/PythonNotes.ipynb
Text
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts
Friday, September 6, 2019
Monday, August 19, 2019
Numpy array multiplication
Dot product
- Applies to one dimensional arrays, aka vectors.
- The sum of the products of the components of the vectors.
- The result supposedly represents “how similar the two vectors are”.
- The first elements of each vector multiplied, then the second, third, etc. Then add them all together.
- Aka inner product
- Aka scalar product. Since the result is a scalar.
- Notation is the two vector names next to each other with a superscripted T above the first.
- In Numpy, the dot method of the first vector is called, passing the second vector as an argument.
Hadamard product
- Can do this on vectors of the same size.
- Result is a vector also that same size.
- The first elements of each vector multiplied and become the first element of the answer. Repeat for all elements.
- Notation is a very small centered circle between the elements.
- In Numpy, the * operator is used.
Matrix multiplication
- Applies to arrays with dimensions higher than one.
- Technically when there is only one dimension in either or both arrays, it is the same process described here, but each row and/or column have only one element, so it can be simpler to think of it only in terms of the "Dot Product" description above.
- In Numpy, a matrix will be an array of arrays
- Can multiply two matrices A and B if the number of [rows, columns] in matrix A is equal to the number of [columns, rows].
- Result is another matrix with the width of B and the height of A.
- Each element of the result is a scalar.
- Each element of the result is the dot product of corresponding rows of A with columns of B.
- The first row of the result is the dot product of the first row of A with each of the columns of B.
- The second row of the result is the dot product of the second row of A with each of the columns of B.
- And so on.
- Notation is the names of the two matrices next to each other.
- In Numpy, the dot method of the first array is called, passing the second array as an argument.
Subscribe to:
Posts (Atom)