tensorflow==2.2.0
一维列表
import tensorflow as tf
## for 1D tensor produce **scalar tensor elements**
dataset = tf.data.Dataset.from_tensor_slices([1,2,3])
print(type(dataset))
for element in dataset:
print(element)
输出
<class 'tensorflow.python.data.ops.dataset_ops.TensorSliceDataset'>
tf.Tensor(1, shape=(), dtype=int32)
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor(3, shape=(), dtype=int32)
二维列表
# slicing a 2D tensor produces 1D tensor elements
import tensorflow as tf
two = [[1,2],[3