Is there an equivalent matlab dot function in numpy?

Is there an equivalent matlab dot function in numpy?

Matlab dot function: For multidimensional arrays A and B, a dot returns the scalar product along the first non-single size A and B. A and B must be the same size.

In numpy, the following is similar, but not equivalent:

 dot (A.conj().T, B) 
+4
source share
3 answers

In MATLAB dot(A,B) two matrices A and B the same size are simple:

 sum(conj(A).*B) 

Equivalent Python / Numpy:

 np.sum(A.conj()*B, axis=0) 
+7
source

Matlab1 example:

A = [1,2,3;4,5,6] B = [7,8,9;10,11,12] dot(A,B)

Result: 47 71 99

Matlab2 example:

sum(A.*B)

Result: 47 71 99

Nump variant of Matlab example2 example:

A = np.matrix([[1,2,3],[4,5,6]]) B = np.matrix([[7,8,9],[10,11,12]]) np.multiply(A,B).sum(axis=0)

Result: matrix ([[47, 71, 99]])

0
source

Check out these cheats.

Numpy contains both an array class and a matrix class. The array class is designed for a general-purpose n-dimensional array for many types of numerical computations, and the matrix is โ€‹โ€‹designed to facilitate linear algebra calculations. In practice, there are only a few key differences between them.

The * operator, dot () and multiply ():
For an array * means multiplication by elements, and the dot () function is used for matrix multiplication.
For a matrix * means multiplication of the matrix, and the multiply () function is used to multiply by elements.

-1
source

All Articles