for in range( shape[ ]) + [iy[ireturn you'll have noticed that the dot product between two vectors is scalar and that only vectors with the same number of elements are compatible for dot product you can also take the dot product between matrix and vector ywhich returns vector where the coefficients are the dot products between and the rows of you implement it as followsimport numpy as np is numpy matrix def naive_matrix_vector_dot(xy)assert len( shape= assert len( shape= assert shape[ = shape[ np zeros( shape[ ]for in range( shape[ ])for in range( shape[ ]) [ + [ijy[jreturn is numpy vector the first dimension of must be the same as the th dimension of ythis operation returns vector of with the same shape as you could also reuse the code we wrote previouslywhich highlights the relationship between matrix-vector product and vector productdef naive_matrix_vector_dot(xy) np zeros( shape[ ]for in range( shape[ ]) [inaive_vector_dot( [ :]yreturn note that as soon as one of the two tensors has an ndim greater than dot is no longer symmetricwhich is to say that dot(xyisn' the same as dot(yxof coursea dot product generalizes to tensors with an arbitrary number of axes the most common applications may be the dot product between two matrices you can take the dot product of two matrices and (dot(xy)if and only if shape[ = shape[ the result is matrix with shape ( shape[ ] shape[ ])where the coefficients are the vector products between the rows of and the columns of here' the naive implementationx and are numpy matrices def naive_matrix_dot(xy)assert len( shape= assert len( shape= assert shape[ = shape[ the first dimension of must be the same as the th dimension of ythis operation returns matrix of with specific shape np zeros(( shape[ ] shape[ ])for in range( shape[ ])iterates over the rows of for in range( shape[ ])and over the columns of row_x [ :column_y [:jz[ijnaive_vector_dot(row_xcolumn_yreturn licensed to