Tensorflow Ragged Tensors

(根据官文,要安装tf-nightly) Ragged Tensors即tf提供的不规则形状,或者说可变元素长度的tensor。 比如: digits = t

(根据官文,要安装tf-nightly)
Ragged Tensors即tf提供的不规则形状,或者说可变元素长度的tensor。
比如:

digits = tf.ragged.constant([[3, 1, 4, 1], [], [5, 9, 2], [6], []])

或者

words = tf.ragged.constant([["So", "long"], ["thanks", "for", "all", "the", "fish"]])

支持的操作如:tf.add, tf.concat, tf.tile, tf.string.substr

需要注意的点:
1不能存储不同的类型,如
tf.ragged.constant([[“one”, “two”], [3, 4]])
2不能存储不同的nested depth,如
tf.ragged.constant([“A”, [“B”, “C”]])
正确的写法应该是:
tf.ragged.constant([[“A”], [“B”, “C”]])