What are the differences between numpy arrays and matrices? Which one should I use?

前端 未结 5 1934
野的像风
野的像风 2020-11-22 07:08

What are the advantages and disadvantages of each?

From what I\'ve seen, either one can work as a replacement for the other if need be, so should I bother using both

5条回答
  •  生来不讨喜
    2020-11-22 07:40

    As others have mentioned, perhaps the main advantage of matrix was that it provided a convenient notation for matrix multiplication.

    However, in Python 3.5 there is finally a dedicated infix operator for matrix multiplication: @.

    With recent NumPy versions, it can be used with ndarrays:

    A = numpy.ones((1, 3))
    B = numpy.ones((3, 3))
    A @ B
    

    So nowadays, even more, when in doubt, you should stick to ndarray.

提交回复
热议问题