# How to make a Tensor from ndarray of type object

**URL:** <https://discuss.pytorch.org/t/how-to-make-a-tensor-from-ndarray-of-type-object/128022>\
**Category:** vision\
**Created:** [July 29, 2021, 9:51am UTC](https://discuss.pytorch.org/t/how-to-make-a-tensor-from-ndarray-of-type-object/128022 "2021-07-29T09:51:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Saqlain](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/muhammad_saqlain/32/40670_2.png) [@Muhammad\_Saqlain](https://discuss.pytorch.org/u/Muhammad_Saqlain)\
**Post date:** [July 29, 2021, 9:51am UTC](https://discuss.pytorch.org/t/how-to-make-a-tensor-from-ndarray-of-type-object/128022/1 "2021-07-29T09:51:39Z")

</div>

I am new to PyTorch. I have an array of length 6 and shape (6, ) when I run torch.from\_numpy(data\_array), I got this error:

TypeError: can’t convert np.ndarray of type numpy.object\_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

I have also tried with pd.DataFrame, but face another error:

TypeError: expected np.ndarray (got DataFrame)

```auto
data_array = np.load('Dance0368.npy', allow_pickle=True)
data = pd.DataFrame(data_array)
len(data_array)
6

data_array.shape
(6,)

torch.from_numpy(data_array)
TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

data.shape
(6, 1)

data.dtypes
0 object
dtype: object

data
	0
0	{'cam': [0.371, -0.4058, 0.0315], 'pose': [-2....
1	{'cam': [0.3848, 0.198, 0.03775], 'pose': [-3....
2	{'cam': [0.5635, 0.684, 0.1471], 'pose': [-3.0...
3	{'cam': [0.3994, 0.4841, 0.01412], 'pose': [-3...
4	{'cam': [0.3486, -0.0975, 0.03378], 'pose': [3...
5	{'cam': [0.401, -0.661, -0.0003161], 'pose': [...

torch.from_numpy(data)
TypeError: expected np.ndarray (got DataFrame)

X = torch.from_numpy(data.values)
TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

torch.Tensor(data)
ValueError: expected sequence of length 6 at dim 0 (got 1)

```

---

<div class="post-metadata">

**Author:** ![knoriy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/knoriy/32/35651_2.png) [@knoriy](https://discuss.pytorch.org/u/knoriy)\
**Post date:** [July 29, 2021, 10:44am UTC](https://discuss.pytorch.org/t/how-to-make-a-tensor-from-ndarray-of-type-object/128022/2 "2021-07-29T10:44:56Z")

</div>

Hi Muhammad,

The problem is caused by the data type you are trying to convert into a `torch.Tensor,` PyTorch doesn’t support complex data structures such as dictionaries.

You can convert your data into PyTorch tensors by:

```auto
data_array = np.array({"cam":[0,1,1], "pos":[0.5,1.3,1.9]})
cam, pos = torch.tensor([data_array.item()["cam"], data_array.item()["pos"]])

```

or

```auto
tensorData= torch.tensor([data_array.item()["cam"], data_array.item()["pos"]])

```

---

<div class="post-metadata">

**Author:** ![bobey](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/bobey/32/43026_2.png) [@bobey](https://discuss.pytorch.org/u/bobey)\
**Post date:** [January 30, 2022, 10:40am UTC](https://discuss.pytorch.org/t/how-to-make-a-tensor-from-ndarray-of-type-object/128022/3 "2022-01-30T10:40:41Z")

</div>

Convert the data to list instead of ndnumpy
