![](/img/trans.png)
[英]Why does numpy have a corresponding function for many ndarray methods?
[英]Why some methods of ndarray are present as an equivalent function in top-level of numpy?
我看到有ndarray.reshape
和numpy.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.