Shun
0
Q:

dot product python

A = [1,2,3,4,5,6]
B = [2,2,2,2,2,2]

# with numpy
import numpy as np
np.dot(A,B) # 42
np.sum(np.multiply(A,B)) # 42
#Python 3.5 has an explicit operator @ for the dot product
np.array(A)@np.array(B)# 42
# without numpy
sum([A[i]*B[i] for i in range(len(B))]) # 42
1
>>> a = [[1, 0], [0, 1]]
>>> b = [[4, 1], [2, 2]]
>>> np.dot(a, b)
array([[4, 1],
       [2, 2]])
1
a = np.array([[1,2],[3,4]]) 
b = np.array([[11,12],[13,14]]) 
np.dot(a,b)
[[37  40], [85  92]] 
1

New to Communities?

Join the community