编程实践(Numpy)上 Task1:数据类型及数组创建(2天)

it2024-07-09  40

熟悉基础常量、常见数据类型,以及时间日期和时间增量的处理。掌握数组的创建和数组的属性。

常量

numpy.nan

numpy.inf

numpy.pi

numpy.e

数据类型

类型备注说明bool_ = bool88位布尔类型int8 = byte8位整型int16 = short16位整型int32 = intc32位整型int_ = int64 = long = int0 = intp64位整型uint8 = ubyte8位无符号整型uint16 = ushort16位无符号整型uint32 = uintc32位无符号整型uint64 = uintp = uint0 = uint64位无符号整型float16 = half16位浮点型float32 = single32位浮点型float_ = float64 = double64位浮点型str = unicode = str0 = unicode Unicode 字符串datetime64 日期时间类型timedelta64 表示两个时间之间的间隔 字符对应类型备注bboolean'b1'isigned integer'i1', 'i2', 'i4', 'i8'uunsigned integer'u1', 'u2' ,'u4' ,'u8'ffloating-point'f2', 'f4', 'f8'ccomplex floating-point mtimedelta64表示两个时间之间的间隔Mdatetime64日期时间类型Oobject S(byte-)stringS3表示长度为3的字符串UUnicodeUnicode 字符串Vvoid 

时间日期和时间增量

datetime64 基础

日期单位代码含义时间单位代码含义Y年h小时M月m分钟W周s秒D天ms毫秒--us微秒--ns纳秒--ps皮秒--fs飞秒--as阿托秒

数组的创建

数组的创建

numpy 提供的最重要的数据结构是ndarray,它是 python 中list的扩展。

1. 依据现有数据来创建 ndarray

(a)通过array()函数进行创建。

(b)通过asarray()函数进行创建

(c)通过fromfunction()函数进行创建

2. 依据 ones 和 zeros 填充方式

(a)零数组

(b)1数组

(c)空数组

(d)单位数组

(e)对角数组

(f)常数数组

3. 利用数值范围来创建ndarray

4. 结构数组的创建

(a)利用字典来定义结构

(b)利用包含多个元组的列表来定义结构

数组的属性

最新回复(0)