numpy从文件直接读入得到数组对象

数组对象

####  numpy数据读取与写出;


测试数据:https://archive.ics.uci.edu/ml/machine-learning-databases/iris/



import numpy as np
import os
os.chdir("D://python_script//")
a = np.loadtxt("iris.data", dtype = float64, delimiter=',', usecols = [0, 1, 2, 3])
print(a)
b = np.loadtxt("iris.data", dtype = "S", delimiter=',', usecols = [4])
print(b)
for x in range(len(b)):
    print(a[x], "is ", b[0])
    
  
    
#指定数据类型,导入数据
t = np.dtype([('sepal_length', 'f'),('sepal_width','f'),('petal_length','f'),('petal_width','f'),('class','S20')])
a = np.loadtxt("iris.data", dtype = t, delimiter=',')
print(a)
r = np.savetxt("iris.csv", a, fmt='%3.1f:%3.1f:%3.1f:%3.1f:%s')


  • 发表于 2019-09-30 15:26
  • 阅读 ( 1973 )
  • 分类:python

0 条评论

请先 登录 后评论
omicsgene
omicsgene

生物信息

654 篇文章

作家榜 »

  1. omicsgene 654 文章
  2. 安生水 325 文章
  3. Daitoue 167 文章
  4. 生物女学霸 120 文章
  5. 红橙子 78 文章
  6. CORNERSTONE 72 文章
  7. rzx 67 文章
  8. xun 66 文章