tensorflow2.0 学习笔记-利用tf.data.Dataset API读取numpy array文件

tensorflow2.0 学习笔记-数据读取1

  • 利用tf.data.Dataset API读取numpy array文件
    • 读取numpy array数据

利用tf.data.Dataset API读取numpy array文件

读取numpy array数据

#导入相关库
import tensorflow as tf 
import numpy as np 
from sklearn import datasets

iris = datasets.load_iris()#下载数据
ds1 = tf.data.Dataset.from_tensor_slices((iris['data'],iris['target']))
for feature, label in ds1.take(5):
    print(feature,label)

#输出结果
tf.Tensor([5.1 3.5 1.4 0.2], shape=(4,), dtype=float64) tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor([4.9 3.  1.4 0.2], shape=(4,), dtype=float64) tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor([4.7 3.2 1.3 0.2], shape=(4,), dtype=float64) tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor([4.6 3.1 1.5 0.2], shape=(4,), dtype=float64) tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor([5.  3.6 1.4 0.2], shape=(4,), dtype=float64) tf.Tensor(0, shape=(), dtype=int32)

你可能感兴趣的:(Tensorflow2.0)