Why does numpy have a corresponding function for many ndarray methods?

前端 未结 3 1563
梦如初夏
梦如初夏 2020-12-01 17:03

A few examples:

numpy.sum()
ndarray.sum()
numpy.amax()
ndarray.max()
numpy.dot()
ndarray.dot()

... and quite a few more. Is it to support s

3条回答
  •  没有蜡笔的小新
    2020-12-01 17:43

    Elaborating on Peter's comment for visibility:

    We could make it more consistent by removing methods from ndarray and sticking to just functions. But this is impossible because it would break everyone's existing code that uses methods.

    Or, we could move all functions to also be methods. But this is impossible because new users and packages are constantly defining new functions. Plus continuing to multiply these duplicate methods violates "there should be one obvious way to do it".

    If we could go back in time then I'd probably argue for not having these methods on ndarray at all, and using functions exclusively. ... So this all argues for using functions exclusively

    numpy issue: More consistency with array-methods #7452

提交回复
热议问题