With the help of tf.data.Dataset.from_tensor_slices()
method, we can get the slices of an array in the form of objects by using tf.data.Dataset.from_tensor_slices()
method.
Syntax : tf.data.Dataset.from_tensor_slices(list)
Return : Return the objects of sliced elements.
Example #1 :
In this example we can see that by using tf.data.Dataset.from_tensor_slices()
method, we are able to get the slices of list or array.
import tensorflow as tf
gfg = tf.data.Dataset.from_tensor_slices([ 1 , 2 , 3 , 4 , 5 ])
for ele in gfg:
print (ele.numpy())
|
Output :
1
2
3
4
5
Example #2 :
import tensorflow as tf
gfg = tf.data.Dataset.from_tensor_slices([[ 5 , 10 ], [ 3 , 6 ]])
for ele in gfg:
print (ele.numpy())
|
Output :
[5, 10]
[3, 6]
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
03 Oct, 2019
Like Article
Save Article