The Python Book | |||
Latest All — By Topic 2019 2016 2015 2014 Topics:
angle argsort beautifulsoup binary bisect clean collinear covariance cut_paste_cli datafaking dataframe datetime day_of_week delta_time df2sql doctest exif floodfill fold format frequency gaussian geocode httpserver is join legend linalg links matrix max namedtuple null numpy oo osm packaging pandas plot point range regex repeat reverse sample_words shortcut shorties sort stemming strip_html stripaccent tools visualization zen zip Tags:
3d aggregation angle archive argsort atan beautifulsoup binary bisect class clean collinear colsum comprehension count covariance csv cut_paste_cli datafaking dataframe datetime day_of_week delta_time deltatime df2sql distance doctest dotproduct dropnull exif file floodfill fold format formula frequency function garmin gaussian geocode geojson gps groupby html httpserver insert ipython is join kfold legend linalg links magic matrix max min namedtuple none null numpy onehot oo osm outer_product packaging pandas plot point quickies range read_data regex repeat reverse sample sample_data sample_words shortcut shorties sort split sqlite stack stemming string strip_html stripaccent tools track tuple visualization zen zip zipfile |
matrix
20160416
Add a column of zeros to a matrix
Add the column:
Watchout: np.c_ takes SQUARE brackets, not parenthesis! There is also an
matrix
20160122
Matrix multiplication : dot product
Dot product of two vectorsTake the first row of above a matrix and the first column of above b matrix:
Normalize a matrixNormalize the columns: suppose the columns make up the features, and the rows the observations. Calculate the 'normalizers':
Turn a into normalized matrix an:
matrix
20150728
Dot product used for aggregation of an unrolled matrixAggregations by column/row on an unrolled matrix, done via dot product. No need to reshape. Column sumsSuppose this 'flat' array ..
.. represents an 'unrolled' 3x4 matrix ..
.. of which you want make the sums by column ..
This can also be done by the dot product of a tiled eye with the array!
Dot product:
Row sumsSimilar story :
Sum by row:
Can be expressed by a Kronecker eye-onesie :
Dot product:
For the np.kron() function see Kronecker product
matrix
20150727
The dot product of two matrices (Eg. a matrix and it's tranpose), equals the sum of the outer products of the row-vectors & column-vectors.
Dot product of A and A^T :
Or as the sum of the outer products of the vectors:
.. added up..
.. and yes it is the same as the dot product! Note: for above, because we are forming the dot product of a matrix with its transpose, we can also write it as (not using the transpose) :
|