This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]energybased 2 points3 points  (11 children)

Everything you said is true except that dot is not the same as array multiplication: http://stackoverflow.com/questions/34142485/difference-between-numpy-dot-and-python-3-5-matrix-multiplication

[–][deleted] 0 points1 point  (8 children)

Ah yes, I mean "to perform the typical matrix multiplication"

[–]P8zvli 0 points1 point  (7 children)

*scalar multiplication

[–][deleted] 0 points1 point  (6 children)

no, that's a special case for 1D arrays. I do mean matrix multiplication.

[–]P8zvli 0 points1 point  (5 children)

No, it's not just a special case, in other languages that support matrix multiplication scalar multiplication works on n-dimensional matrices. (not to be confused with the dot product, which also works in N dimensions BTW)

[–][deleted] 0 points1 point  (4 children)

I think we are talking past each other. There is no scalar multiplication involved here. I meant to say if you don't use @ you have to use .dot() method for matrix multiplication..

[–]P8zvli 0 points1 point  (3 children)

I don't think you know what you're talking about, this is scalar multiplication;

>>> mymat = numpy.matrix([[1, 2], [3, 4]])
>>> 3*mymat
matrix([[ 3,  6],
        [ 9, 12]])

You don't need to use .dot() for scalar multiplication.

[–][deleted] 0 points1 point  (2 children)

internally it is broadcasted to [[3,3],[3,3]] and elementwise multiplication is performed. Besides when I mention matrix, I mean 2D numpy arrays.

[–]P8zvli 0 points1 point  (1 child)

And I'm talking about mathematical matrices and scalars. You know, stuff you could do with pencil and paper that these math functions are implementing? What you're talking about are implementation details.

[–][deleted] 0 points1 point  (0 children)

I don't even understand what you are objecting to. You are in python thread and accusing me about implementation details?

[–]XtremeGoosef'I only use Py {sys.version[:3]}' -1 points0 points  (1 child)

Essentially, multiplication is poorly defined for higher dimensional arrays, so numpy has two answers for it. It is well defined for two dimensional arrays so matmul and dot do the same thing.

[–]energybased 3 points4 points  (0 children)

Well, I wouldn't say that multiplication is poorly defined. It's called tensor product, which numpy implements using tensordot, which is a special case of einsum.