2

Can I append elements or extend in some way Ragged Tensors as I can do nested lists ?

In [158]: l=[[1,2],[3],[4,5,6]]                                                                                                                                              

In [159]: l                                                                                                                                                                  
Out[159]: [[1, 2], [3], [4, 5, 6]]

In [160]: l[1]                                                                                                                                                               
Out[160]: [3]

In [161]: l[1].append(9)                                                                                                                                                     

In [162]: l                                                                                                                                                                  
Out[162]: [[1, 2], [3, 9], [4, 5, 6]]

Or for that matter can any Tensor be dynamically resized (not reshaped)

sten
  • 7,028
  • 9
  • 41
  • 63

1 Answers1

1

RaggedTensors are not dynamic. However, you can use tf.concat with another RaggedTensor containing your update to create a new RaggedTensor:

>>> rt = tf.ragged.constant([[1,2],[3],[4,5,6]])
>>> update = tf.ragged.constant([[],[9],[]])
>>> tf.concat([rt,update],axis=1)
<tf.RaggedTensor [[1, 2], [3, 9], [4, 5, 6]]>
Lescurel
  • 10,749
  • 16
  • 39