小编inV*_*der的帖子

为什么有些numpy调用没有作为方法实现?

我一直认为Python是一种高度面向对象的编程语言.最近,我一直在使用numpy很多,我开始想知道为什么有很多东西只作为函数实现,而不是作为numpy.array(或ndarray)对象的方法.

a例如,如果我们有一个给定的数组,你可以这样做

a = np.array([1, 2, 3])

np.sum(a)
>>> 6
a.sum()
>>> 6
Run Code Online (Sandbox Code Playgroud)

看起来很好,但有很多调用不能像以下一样工作:

np.amax(a)
>>> 3
a.amax()
>>> AttributeError: 'numpy.ndarray' object has no attribute 'amax'
Run Code Online (Sandbox Code Playgroud)

我发现这令人困惑,不直观,我认为没有任何理由.不过,可能会有一个好的; 也许有人可以开导我.

python numpy

8
推荐指数
1
解决办法
1252
查看次数

标签 统计

numpy ×1

python ×1