借助tf.data.Dataset.from_tensor_slices()
方法,我們可以通過使用對象的形式獲取數組的切片tf.data.Dataset.from_tensor_slices()
方法。
用法:tf.data.Dataset.from_tensor_slices(list)
返回:Return the objects of sliced elements.
範例1:
在這個例子中,我們可以通過使用tf.data.Dataset.from_tensor_slices()
方法,我們可以獲取列表或數組的切片。
# import tensorflow
import tensorflow as tf
# using 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())
輸出:
1
2
3
4
5
範例2:
# import tensorflow
import tensorflow as tf
# using 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())
輸出:
[5, 10]
[3, 6]
相關用法
- Python tensorflow.eye()用法及代碼示例
- Python tensorflow.get_static_value()用法及代碼示例
- Python tensorflow.gradients()用法及代碼示例
- Python tensorflow.expand_dims()用法及代碼示例
- Python tensorflow.fingerprint()用法及代碼示例
- Python tensorflow.fill()用法及代碼示例
- Python tensorflow.GradientTape()用法及代碼示例
- Python tensorflow.guarantee_const()用法及代碼示例
- Python tensorflow.math.less()用法及代碼示例
- Python tensorflow.gather()用法及代碼示例
- Python tensorflow.gather_nd()用法及代碼示例
- Python tensorflow.get_logger()用法及代碼示例
- Python tensorflow.histogram_fixed_width()用法及代碼示例
- Python tensorflow.raw_ops.Cos()用法及代碼示例
- Python tensorflow.math.sin()用法及代碼示例
- Python tensorflow.math.erf()用法及代碼示例
- Python tensorflow.math.cos()用法及代碼示例
- Python tensorflow.identity_n()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Tensorflow | tf.data.Dataset.from_tensor_slices()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。