这个函数就是将输入的张量,按第一维度切分成多个小的张量。代码如下:
import tensorflow as tf
b = tf.random.normal([3, 1, 2, 1])
bb = tf.data.Dataset.from_tensor_slices(b)
print(bb)
print('-----------------------')
for i in bb:
print(i)
输出的结果如下:
<TensorSliceDataset shapes: (1, 2, 1), types: tf.float32>
-----------------------
tf.Tensor(
[[[-0.53834546]
[ 0.6661047 ]]], shape=(1, 2, 1), dtype=float32)
tf.Tensor(
[[[-0.44865417]
[ 0.5713346 ]]], shape=(1, 2, 1), dtype=float32)
tf.Tensor(
[[[-1.2513908 ]
[-0.60661495]]], shape=(1, 2, 1), dtype=float32)
Process finished with exit code 0