5 ms·
Is the np.dot -> @ tip reliable? I thought these were fairly different in practice.
by iandanforth 9y ago
Is the np.dot -> @ tip reliable? I thought these were fairly different in practice.
- deleted 9y ago[deleted]
- gh02t 9y agoWhat do you mean? `A.dot(B)` and `A @ B` are the same thing for NumPy arrays. You might be mixing it up with the weirdness of `array` versus `matrix`, but that's totally separate.
- iandanforth 9y agoI was thinking of this - https://stackoverflow.com/questions/34142485/difference-between-numpy-dot-and-python-3-5-matrix-multiplication https://stackoverflow.com/questions/34142485/difference-betw...
- pletnes 9y agoThe @ operator is the same as np.matmul which is different from np.dot for matrices of rank >=3.
- dagw 9y agoAnother difference is that B can be a scalar in the statement A.dot(B), but not in A @ B
- gh02t 9y agoAh you're right, I had that mixed up. matmul should generally be the desired behavior anyway I'd think, the previous behavior of dot was a bit weird IMO, especially the behavior with a scalar. It's not backwards compatible, but I think it'd be better to prefer @/matmul in the future anyway. I almost think it'd be nice to make matmul undefined for ranks higher than 2, since it's not really matrix multiplication and if you want to do that (or the previous behavior of dot) it can be achieved with einsum, with the advantage that you have to be a lot more explicit about what sort of tensor multiplication you want. That's probably a bit too purist though.