Flux tensor | tf.data.Dataset.from_tensor_slices ()

NumPy | Python Methods and Functions

Using the tf.data.Dataset.from_tensor_slices() method, we can get fragments of an array as objects using tf.data.Dataset.from_tensor_slices ( ) .

Syntax: tf.data.Dataset.from_tensor_slices (list)
Return : Return the objects of sliced ​​elements.

Example # 1:
In this example, we can see that with tf.data.Dataset.from_tensor_slices () we can get fragments of a list or array.

# import flow tensor

import tensorflow as tf

 
# using the tf.data.Dataset.from_tensor_slices () method

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 ь tensor flow

import tensorflow as tf

 
# using the tf.data.Dataset.from_tensor_slices () method

gfg = tf.data.Dataset.from_tensor_slices ([[ 5 , 10 ], [ 3 , 6 ]])

 

for ele in gfg:

print (ele.numpy ())

Output:

[5, 10]
[3, 6]





Get Solution for free from DataCamp guru