代码来源于官方文档,做了一些小小的调整:

  1. # -*- coding:utf-8 -*-
  2. import tensorflow as tf
  3.  
  4. filename_queue = tf.train.string_input_producer(["file01.csv", "file02.csv"])
  5. reader = tf.TextLineReader()
  6. key, value = reader.read(filename_queue)
  7.  
  8. # Default values, in case of empty columns. Also specifies the type of the
  9. # decoded result.
  10. record_defaults = [[1], [1], [1]]
  11. col1, col2, col3 = tf.decode_csv(value, record_defaults = record_defaults)
  12. features = tf.stack([col1, col2])
  13.  
  14. init_op = tf.global_variables_initializer()
  15. local_init_op = tf.local_variables_initializer() # local variables like epoch_num, batch_size 可以不初始化local
  16. with tf.Session() as sess:
  17. sess.run(init_op)
  18. sess.run(local_init_op)
  19.  
  20. # Start populating the filename queue.
  21. coord = tf.train.Coordinator()
  22. threads = tf.train.start_queue_runners(coord=coord)
  23.  
  24. for i in range(5):
  25. # Retrieve a single instance:
  26. example, label = sess.run([features, col3])
  27. print(example)
  28. print(label)
  29.  
  30. coord.request_stop()
  31. coord.join(threads)

file01.csv 和 file02.csv 格式一样:

  1. 19,3,1
  2. 10,2,3
  3. 11,3,1
  4. 12,4,2
  5. 17,5,1
  6. 18,6,2
  7. ......

TensorFlow读取CSV数据的更多相关文章

  1. TensorFlow读取CSV数据(批量)

    直接上代码: # -*- coding:utf-8 -*- import tensorflow as tf def read_data(file_queue): reader = tf.TextLin ...

  2. Java读取CSV数据并写入txt文件

    读取CSV数据并写入txt文件 package com.vfsd; import java.io.BufferedWriter; import java.io.File; import java.io ...

  3. java 读取CSV数据并写入txt文本

    java 读取CSV数据并写入txt文本 package com.vfsd; import java.io.BufferedWriter; import java.io.File; import ja ...

  4. tensorflow读取训练数据方法

    1. 预加载数据 Preloaded data # coding: utf-8 import tensorflow as tf # 设计Graph x1 = tf.constant([2, 3, 4] ...

  5. PHP读取CSV数据写入数据库

    /*读取csv文件*/ public function testCsv(){ $fileName = "tel.csv"; $fp=fopen($fileName,"r& ...

  6. Tensorflow读取csv文件(转)

    常用的直接读取方法实例:#加载包 import tensorflow as tf import os #设置工作目录 os.chdir("你自己的目录") #查看目录 print( ...

  7. pandas读取csv数据时设置index

    比如读取数据时想把第一列设为index,那么只需要简单的 pd.read_csv("new_wordvecter.csv",index_col=[0]) 这里index_col可以 ...

  8. python 读取csv 数据并画图分析

    数据源 : https://pan.baidu.com/s/1eR593Uy    密码: yqjh python环境 python3 #encoding: utf-8 import csv impo ...

  9. matlab读取csv文件数据并绘图

    circle.m(画二维圆的函数) %该函数是画二维圆圈,输入圆心坐标和半径%rectangle()函数参数‘linewidth’修饰曲线的宽度%'edgecolor','r',edgecolor表示 ...

随机推荐

  1. ThinkPHP框架 做个简单表单 添加数据例子__ACTION__ __SELF__

    public function zhuCe(){//自定义zhuCe方法和zhuCe显示表里的__ACTiON__这个相互交接 //实现两个逻辑 //1,显示注册页面 //2.向数据库添加内容 //自 ...

  2. VUE----整理

    -------------------------------------------------------------------VUE------------------------------ ...

  3. ie9 form submit 请求参数问题替代办法

    //隐藏表单 <input id="hdPeriod" name="period" type="hidden" value=" ...

  4. .NET Core开发日志——Entity Framework与PostgreSQL

    Entity Framework在.NET Core中被命名为Entity Framework Core.虽然一般会用于对SQL Server数据库进行数据操作,但其实它还支持其它数据库,这里就以Po ...

  5. .NET Core开发日志——视图与页面

    当一个Action完成它的任务后,通常需要返回一个实现IActionResult的对象,而最常见的就是View或者ViewResult,所谓的视图对象.那么视图与最终所看到的页面之间的联系又是怎样形成 ...

  6. 访问Google的办法

    访问Google的办法 http://www.liu16.com/g.html http://ac.scmor.com/ https://www.elastic.co/guide/en/elastic ...

  7. iOS中UITableView的一些问题思考

    UITableview的数据源为什么是代理,而不是引用? 我的理解,一般情况下控制器会引用tableView, 数据源和代理方法都是tableView的一个若引用,出了“tableView.datas ...

  8. char是所有类型中最短的 char多为8位,

    https://en.wikipedia.org/wiki/C_data_typesIn practice, char is usually eight bits in size and short ...

  9. 单KEY业务,数据库水平切分架构实践 | 架构师之路

    https://mp.weixin.qq.com/s/8aI9jS0SXJl5NdcM3TPYuQ 单KEY业务,数据库水平切分架构实践 | 架构师之路 原创: 58沈剑 架构师之路 2017-06- ...

  10. [network] netfilter

    netfilter 是什么? netfilter.org is home to the software of the packet filtering framework inside the Li ...