-
np.array函数的作用:列表不存在维度问题,但数组是有维度的,而np.array()的作用就是把列表转化为数组,也可以说是用来产生数组。
-
numpy document中对list和numpy array区别的解释:
【3.5 What’s the difference between a Python list and a NumPy array?】
NumPy gives you an enormous range of fast and efficient ways of creating arrays and manipulating numerical data inside them. While a Python list can contain different data types within a single list, all of the elements in a NumPy array should be homogeneous. The mathematical operations that are meant to be performed on arrays would be extremely inefficient if the arrays weren’t homogeneous.
Why use NumPy?
NumPy arrays are faster and more compact than Python lists. An array consumes less memory and is convenient to use. NumPy uses much less memory to store data and it provides a mechanism of specifying the data types. This allows the code to be optimized even further.
总结起来就是:
(1)numpy array[数组]中的元素要是同类型的;
(2)numpy array更快更紧凑,占用的空间更小,而且它提供了一种指定数据类型的机制。 -
numpy.array 常用变量及参数:
dtype变量:用来存放数据类型, 创建数组时可以同时指定。
object:必选参数,类型为array_like。
copy:可选参数,类型为bool值。如果为true(默认值),则复制对象。
shape变量:存放数组的大小, 这人值是可变的, 只要确保无素个数不变的情况下可以任意修改。(-1为自动适配, 保证个数不变)
numpy.array的作用
最新推荐文章于 2024-05-08 11:29:43 发布