CopyPastor

Detecting plagiarism made easy.

Score: 0.809721476001238; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2022-06-25
by Jagroop

Original Post

Original - Posted on 2015-12-07
by Alex Riley



            
Present in both answers; Present only in the new answer; Present only in the old answer;

The @ operator calls the array's __matmul__ method, not dot. This method is also present in the API as the function np.matmul.
>>> a = np.random.rand(8,13,13) >>> b = np.random.rand(8,13,13) >>> np.matmul(a, b).shape
(8, 13, 13)
From the documentation:
matmul differs from dot in two important ways.
Multiplication by scalars is not allowed. Stacks of matrices are broadcast together as if the matrices were elements. The last point makes it clear that dot and matmul methods behave differently when passed 3D (or higher dimensional) arrays. Quoting from the documentation some more:
For matmul:
If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly.
For np.dot:
For 2-D arrays it is equivalent to matrix multiplication, and for 1-D arrays to inner product of vectors (without complex conjugation). For N dimensions it is a sum product over the last axis of a and the second-to-last of b

For More Info : https://stackoverflow.com/questions/34142485/difference-between-numpy-dot-and-python-3-5-matrix-multiplication
The `@` operator calls the array's `__matmul__` method, not `dot`. This method is also present in the API as the function [`np.matmul`](https://numpy.org/doc/stable/reference/generated/numpy.matmul.html).
>>> a = np.random.rand(8,13,13) >>> b = np.random.rand(8,13,13) >>> np.matmul(a, b).shape (8, 13, 13)
From the documentation:
> `matmul` differs from `dot` in two important ways. > > - Multiplication by scalars is not allowed. > - Stacks of matrices are broadcast together as if the matrices were elements.
The last point makes it clear that `dot` and `matmul` methods behave differently when passed 3D (or higher dimensional) arrays. Quoting from the documentation some more:
For `matmul`:
> If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly.
For [`np.dot`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.html):
> For 2-D arrays it is equivalent to matrix multiplication, and for 1-D arrays to inner product of vectors (without complex conjugation). *For N dimensions it is a sum product over the last axis of a and the second-to-last of b*

        
Present in both answers; Present only in the new answer; Present only in the old answer;