""" 查看数据类型并修改操作 """ import numpy as np print("--------------常用数据类型----------------") # 默认整数int32,小数float64 a = np.array([1, 1, 1]) b = np.array([1., 1, 1]) c = np.array([1, 1, 1], dtype=np.float32) d = np.array([1, 1, 1], dtype=np.string_) print("整型:", a.dtype) print("浮点数:", b.dtype) print("浮点数:", c.dtype) print("字节数组:", d.dtype) print("--------------数据类型修改----------------") a = np.array([1, 2, 3, 4, 5]) print("字节数组:", a.tostring()) print("浮点数:", a.astype(np.float32))
整型: int32 浮点数: float64 浮点数: float32 字节数组: |S1 --------------数据类型修改---------------- 字节数组: b'x01x00x00x00x02x00x00x00x03x00x00x00x04x00x00x00x05x00x00x00' 浮点数: [1. 2. 3. 4. 5.]