What's the workaround for "ragged/jagged tensors" in PyTorch?
Asked Answered
B

1

14

Tensorflow provides ragged tensors (https://www.tensorflow.org/guide/ragged_tensor). PyTorch however doesn't provide such a data structure. Is there a workaround to construct something similar in PyTorch?

import numpy as np
x = np.array([[0], [0, 1]])
print(x)  # [list([0]) list([0, 1])]

import tensorflow as tf
x = tf.ragged.constant([[0], [0, 1]])
print(x)  # <tf.RaggedTensor [[0], [0, 1]]>

import torch
# x = torch.Tensor([[0], [0, 1]])  # ValueError
Breeches answered 8/10, 2019 at 14:0 Comment(0)
E
12

PyTorch is implementing something called NestedTensors which seems to have pretty much the same purpose as RaggedTensors in Tensorflow. You can follow the RFC and progress here.

Exceptional answered 26/10, 2019 at 1:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.