Program for dot product and cross product of two vectors | Python3 implementation for dot product and cross product of two vector . ; Function that return dot product of two vector array . ; Loop for calculate cot product ; Function to find cross product of two vector array . ; Driver function ; dotProduct function call ; crossProduct function call ; Loop that print cross product of two vector array .
n = 3 NEW_LINE def dotProduct ( vect_A , vect_B ) : NEW_LINE INDENT product = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT product = product + vect_A [ i ] * vect_B [ i ] NEW_LINE DEDENT return product NEW_LINE DEDENT def crossProduct ( vect_A , vect_B , cross_P ) : NEW_LINE INDENT cross_P . append ( vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ) NEW_LINE cross_P . append ( vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ) NEW_LINE cross_P . append ( vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT vect_A = [ 3 , - 5 , 4 ] NEW_LINE vect_B = [ 2 , 6 , 5 ] NEW_LINE cross_P = [ ] NEW_LINE print ( " Dot ▁ product : " , end = " ▁ " ) NEW_LINE print ( dotProduct ( vect_A , vect_B ) ) NEW_LINE print ( " Cross ▁ product : " , end = " ▁ " ) NEW_LINE crossProduct ( vect_A , vect_B , cross_P ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( cross_P [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT