Python 数据类型转换操作

来源:互联网 发布:路由器ip绑定mac地址 编辑:程序博客网 时间:2024/06/06 02:23

数据类型转换的一些操作

  1. string表示数值的list列表转为int/float型列表

    # python 3.5a = ['1', '2', '3']b = list(map(int, a)) # 转为整型c = list(map(float, a)) # 转为浮点型
  2. text/string转为numpy中ndarray类型

    # python 3.5, numpy 1.12# 数据输入格式为数字以‘,’分隔import numpy as npline = '1,2,3,4,5'x = np.fromstring(line, dtype=int, sep=',')
0 0