Multidimensional arrays in a Dataset
{'login': 'vermouthmjl', 'id': 3142085, 'node_id': 'MDQ6VXNlcjMxNDIwODU=', 'avatar_url': 'https://avatars.githubusercontent.com/u/3142085?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/vermouthmjl', 'html_url': 'https://github.com/vermouthmjl', 'followers_url': 'https://api.github.com/users/vermouthmjl/followers', 'following_url': 'https://api.github.com/users/vermouthmjl/following{/other_user}', 'gists_url': 'https://api.github.com/users/vermouthmjl/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/vermouthmjl/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/vermouthmjl/subscriptions', 'organizations_url': 'https://api.github.com/users/vermouthmjl/orgs', 'repos_url': 'https://api.github.com/users/vermouthmjl/repos', 'events_url': 'https://api.github.com/users/vermouthmjl/events{/privacy}', 'received_events_url': 'https://api.github.com/users/vermouthmjl/received_events', 'type': 'User', 'site_admin': False}
[]
[]
['Hi !\r\n\r\nThis is actually supported ! but not yet in `from_pandas`.\r\nYou can use `from_dict` for now instead:\r\n```python\r\nfrom datasets import Dataset, Array2D, Features, Value\r\nimport pandas as pd\r\nimport numpy as np\r\n\r\ndataset = {\r\n    \'bbox\': [\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]])\r\n    ],\r\n    \'input_ids\': [1, 2, 3, 4]\r\n}\r\ndataset = Dataset.from_dict(dataset)\r\n```\r\n\r\nThis will work but to use it with the torch formatter you must specify the `Array2D` feature type in order to tell the shape:\r\n```python\r\nfrom datasets import Dataset, Array2D, Features, Value\r\nimport pandas as pd\r\nimport numpy as np\r\n\r\ndataset = {\r\n    \'bbox\': [\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),\r\n        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]])\r\n    ],\r\n    \'input_ids\': [1, 2, 3, 4]\r\n}\r\ndataset = Dataset.from_dict(dataset, features=Features({\r\n    "bbox": Array2D(shape=(3, 4), dtype="int64"),\r\n    "input_ids": Value("int64")\r\n}))\r\ndataset.set_format("torch")\r\nprint(dataset[0][\'bbox\'])\r\n# tensor([[1, 2, 3, 4],\r\n#         [1, 2, 3, 4],\r\n#         [1, 2, 3, 4]])\r\n```\r\nIf you don\'t specify the `Array2D` feature type, then the inferred type will be Sequence(Sequence(Value("int64"))) and therefore the torch formatter will return list of tensors'
 'Thanks for the explanation. \r\nWith my original DataFrame, I did\r\n```\r\ndataset = dataset.to_dict("list")\r\n```\r\nand then the rest of the transformation from dictionary works just fine.']
Hi,

I'm trying to put together a `datasets.Dataset` to be used with LayoutLM which is available in `transformers`. This model requires as input the bounding boxes of each of the token of a sequence. This is when I realized that `Dataset` does not support multi-dimensional arrays as a value for a column in a row.

The following code results in conversion error in pyarrow (`pyarrow.lib.ArrowInvalid: ('Can only convert 1-dimensional array values', 'Conversion failed for column bbox with type object')`)

```
from datasets import Dataset
import pandas as pd
import numpy as np

dataset = pd.DataFrame({
    'bbox': [
        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),
        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),
        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),
        np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]])
    ],
    'input_ids': [1, 2, 3, 4]
})
dataset = Dataset.from_pandas(dataset)
```

Since I wanted to use pytorch for the downstream training task, I also tried a few ways to directly put in a column of 2-D pytorch tensor in a formatted dataset, but I can only have a list of 1-D tensors, or a list of arrays, or a list of lists.

```
import torch
from datasets import Dataset
import pandas as pd

dataset = pd.DataFrame({
    'bbox': [
        [[1,2,3,4],[1,2,3,4],[1,2,3,4]],
        [[1,2,3,4],[1,2,3,4],[1,2,3,4]],
        [[1,2,3,4],[1,2,3,4],[1,2,3,4]],
        [[1,2,3,4],[1,2,3,4],[1,2,3,4]]
    ],
    'input_ids': [1, 2, 3, 4]
})
dataset = Dataset.from_pandas(dataset)

def test(examples):
    return {'bbbox': torch.Tensor(examples['bbox'])}
dataset = dataset.map(test)
print(dataset[0]['bbox'])
print(dataset[0]['bbbox'])

dataset.set_format(type='torch', columns=['input_ids', 'bbox'], output_all_columns=True)
print(dataset[0]['bbox'])
print(dataset[0]['bbbox'])

def test2(examples):
    return {'bbbox': torch.stack(examples['bbox'])}
dataset = dataset.map(test2)

print(dataset[0]['bbox'])
print(dataset[0]['bbbox'])
```

Is is possible to support n-D arrays/tensors in datasets? 
It seems that it can also be useful for this [feature request](https://github.com/huggingface/datasets/issues/263).
{'url': 'https://api.github.com/repos/huggingface/datasets/issues/2080/reactions', 'total_count': 0, '+1': 0, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0}