繁体   English   中英

为什么 ndarray 的某些方法在 numpy 的顶层中作为等效的 function 存在?

[英]Why some methods of ndarray are present as an equivalent function in top-level of numpy?

我看到有ndarray.reshapenumpy.reshape并且文档提到它们是等效的。 对于ravel也是如此。 如果是这样,为什么他们在 numpy 命名空间中对这些方法进行不必要的重复,同时还打破了禅宗原则之一

应该有一种——最好只有一种——明显的方法来做到这一点。

It's actually numpy.ndarray.reshape and numpy.reshape , the numpy authors chose to make the reshape function more accessible this way. 我个人认为numpy.reshape比另一个明显得多。

此外,这允许不同的模式:

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

# Using numpy.reshape
np.reshape(x, (1, 3))
# array([[1, 2, 3]])

# Wouldn't be possible without numpy.ndarray.reshape
x.reshape(1, 3)
# array([[1, 2, 3]])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM