Numpy的array数组操作
2017-03-23 23:02
471 查看
Numpy的array数组操作
(一边学一边更新)源文件
import numpy world_alcohol = numpy.genfromtxt("E:\machinelearning\machinelearninginaction\Ch02\datingTestSet.txt",delimiter="\t") print(type(world_alcohol)) world_alcohol
nan:无法转换文档中文件格式,默认转换的类型是float,修改类型需要自己设置dtype属性
import numpy world_alcohol = numpy.genfromtxt("E:\machinelearning\machinelearninginaction\Ch02\datingTestSet.txt",delimiter="\t",dtype='str') print(type(world_alcohol)) world_alcohol
#去掉第一行 import numpy world_alcohol = numpy.genfromtxt("E:\machinelearning\machinelearninginaction\Ch02\datingTestSet.txt",delimiter="\t",dtype='U75',skip_header=1) print(type(world_alcohol)) world_alcohol
首行文字不需要,删除掉,可以设置skip_header=1
#向量(一维数组) vector = numpy.array([5,10,15,20]) print vector vector.dtype #前三个 print(vector[0:3]) print(vector[0:1])
#二维数组 matrix = numpy.array( [ [54563546,1056786,15635465],[27860,22896789,36872],[50006000,68400000000,45400000000000] ] ) print matrix #科学计数法该如何表示呢? #所有行的第一列 print '==============================================================' print matrix[:,1] #所有行的前两列 print matrix[:,0:2]
相关文章推荐
- Python-Numpy(2)Array数组操作
- numpy的array数组操作
- Flex与.NET互操作(十五):使用FluorineFx中的字节数组(ByteArray)实现图片上传 推荐
- Flex与.NET互操作(十五):使用FluorineFx中的字节数组(ByteArray)实现图片上传
- ByteArrayInputStream 和 ByteArrayOutputStream 可以直接操作byte数组的流对象
- ActionScript3(AS3)类库学习之(二)——掌握Array和Vector数组操作
- 数组操作工具类 (实现集合类部分功能,用于Array的增、删、改、查等操作)
- 浅谈C#中的数组类System.Array 操作
- Python列表list 数组array常用操作集锦
- JS 操作Array数组的属性和方法
- Javascrip-js操作数组-Array-添加-修改数组-charje的博客
- (转)Iphone数组一些基础操作 NSArray/NSMutableArray
- Array类对数组的操作
- Python 列表 list 数组 array 常用操作集锦
- Python中Array的常用操作(三)数组高级操作
- JS ARRAY 数组操作
- Flex与.NET互操作(十五):使用FluorineFx中的字节数组(ByteArray)实现图片上传
- Python之路——numpy各函数简介之生成数组函数(Array creation routines)
- Iphone数组一些基础操作 NSArray/NSMutableArray
- Python 列表 list 数组 array 常用操作集锦