Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

dot product python

def dot_product(vector_a, vector_b):
	#base case
    #error message if the vectors are not of the same length
	if len(vector_a) != len(vector_b):
		return "ERROR: both input vectors must be of the same length"

    #multiply vector_a at position i with vector_b at position i
    #sum the vector made
    #return that vector
	return sum([vector_a[i] * vector_b[i] for i in range(len(vector_a))])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dot #product #python
ADD COMMENT
Topic
Name
1+4 =