3 ms·
Currently, we can use * to multiply two numpy matrix. We'll have two choices, * and @, to do the matrix multiply things in numpy. Is it pythonic? Or should we
by waitingkuo 13y ago
Currently, we can use * to multiply two numpy matrix. We'll have two choices, * and @, to do the matrix multiply things in numpy. Is it pythonic? Or should we deprecate * ?
- apl 13y agoNo, we should deprecate numpy.matrix which is the culprit here. If there's only numpy.ndarray, the semantics are absolutely clear: * for element-wise multiplication and @ for "proper" multiplication of two matrices.
- danohuiginn 13y agoThe PEP explains this: "In numerical code, there are two important operations which compete for use of Python's * operator: elementwise multiplication, and matrix multiplication" The idea is to keep using * for elementwise multiplication, and use @ for matrix multiplication.
- dragonwriter 13y agoAdding @ for matrix multiplication is to enable a consistent matrix API for python where * is always elementwise multiplication. Numpy -- and other major projects that use * for matrix multiplication in APIs, as reported in the PEP -- have committed to migrate to the new standard approach once the PEP is implemented.