numpy中的ndarray与array的区别、不同

翻译自stackoverflow上的回答
https://stackoverflow.com/questions/15879315/what-is-the-difference-between-ndarray-and-array-in-numpy

问:What is the difference between ndarray and array in Numpy? And where can I find the implementations in the numpy source code?
(Numpy中ndarray和array的区别是什么?我在哪儿能够找到numpy中相应的实现?)

答:Well, np.array is just a convenience function to create an ndarray, it is not a class itself.
(嗯,np.array只是一个便捷的函数,用来创建一个ndarray,它本身不是一个类)

You can also create an array using np.ndarray, but it is not the recommended way. From the docstring of np.ndarray:
(你也能够用np.ndarray来创建,但这不是推荐的方式。来自np.ndarray的文档:)

Arrays should be constructed using array, zeros or empty … The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array.
(Arrays 应该能用array,zeros 或empty来构造…这里的参数和一个实例化array的低层方法与有关)

Most of the meat of the implementation is in C code, here in multiarray, but you can start looking at the ndarray interfaces here:
https://github.com/numpy/numpy/blob/master/numpy/core/numeric.py

猜你喜欢

转载自blog.csdn.net/peopleqinlei/article/details/77985938