Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have two lists, one is named as A, another is named as B. Each element in A is a triple, and each element in B is just a number. I would like to calculate the result defined as :

result = A[0][0] * B[0] + A[1][0] * B[1] + ... + A[n-1][0] * B[n-1]

I know the logic is easy but how to write in a pythonic way?

Thanks!

1 Answer

0 votes
by (106k points)

You can use the below-mentioned code to calculate the dot product in python:-

import numpy 

result = numpy.dot( numpy.array(A)[:,0], B)

Related questions

0 votes
1 answer
asked Jan 20, 2021 in Python by ashely (50.2k points)
0 votes
1 answer
asked Jul 27, 2019 in Data Science by sourav (17.6k points)
0 votes
1 answer
0 votes
4 answers

Browse Categories

...