在Tensorflow中加载NumPy数据
在这篇文章中,我们将研究在Tensorflow中用Python编程语言加载Numpy数据的方法。
使用tf.data.Dataset.from_tensor_slices()函数
在这种方法下,我们使用tf.data.Dataset.from_tensor_slices()方法加载一个Numpy数组,我们可以通过使用TensorFlow模块中的tf.data.Dataset.from_tensor_slices()方法以对象的形式获得数组的片断。
语法 : tf.data.Dataset.from_tensor_slices(list)
返回:返回被切片元素的对象。
示例 1:
在这个例子中,我们使用tf.data.Dataset.from_tensor_slices()方法,来获取二维阵列的切片,然后将其加载到变量gfg中。
输出:
示例 2:
在这个例子中,我们将使用Python编程语言中TensorFlow库的tf.data.Dataset.from_tensor_slices()函数加载变量gfg的NumPy列表。
输出: