Numpy数组是一个多维数组,简称为ndarray;注意数组的下标是从零开始的,数组里的数据类型应该是一样的
ndarray的随机创建
1、通过numpy.random生成随机数据
示例代码:

ndarray的序列创建
1.np.array(collection)
collection为序列型对象(list)、嵌套序列对象(list of list)
示例代码:

2. np.zeros()
指定大小的全0数组。注意:第一个参数是元组,用来指定大小,如(3, 4)。
3. np.ones()
指定大小的全1数组。注意:第一个参数是元组,用来指定大小,如(2, 3)。

4. np.arange() 和 reshape()
arange() 类似 python 的 range() ,创建一个一维 ndarray 数组。
reshape() 将 重新调整数组的维数。

ndarray的数据类型
1. dtype参数
指定数组的数据类型,类型名+位数,如float64, int32
2. astype方法
转换数组的数据类型
示例代码:

网友评论