# What exactly is a tensor?

**URL:** <https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861>\
**Category:** Uncategorized\
**Created:** [October 19, 2017, 6:31pm UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861 "2017-10-19T18:31:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BroccoliFever](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/broccolifever/32/27791_2.png) [@BroccoliFever](https://discuss.pytorch.org/u/BroccoliFever)\
**Post date:** [October 19, 2017, 6:31pm UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861/1 "2017-10-19T18:31:52Z")

</div>

I am new to machine learning, and I am taking an online class to develop an AI. I would like to understand how it all works, rather than just copying the code so I can implement my own AIs in the future, but my first question is what exactly is a tensor? From what I can find online, it is basically a multi-dimensional array.

For instance, a tensor with size [2, 2, 2] means that there is there is a 3-d array with size 2x2x2. If I were to extend that to [2, 2, 2, 2], each dimension of the 3-d object would have an additional dimension. Is that correct? So a [2, 2, 2, 2] array would hold 16 objects (2x2x2x2 = 16)?

If that is the case, what is the benefit of using a tensor object versus simply a numpy array? Can a tensor hold additional data or are there things that can be done on a tensor that cannot be done in a numpy array?

Thanks to all who aid me in the beginning of my adventure into machine learning!

---

<div class="post-metadata">

**Author:** ![richard](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/richard/32/1861_2.png) [@richard](https://discuss.pytorch.org/u/richard)\
**Post date:** [October 19, 2017, 6:35pm UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861/2 "2017-10-19T18:35:34Z")

</div>

A tensor of size (2, 2, 2, 2) is four-dimensional. Yes, it can hold 2 \* 2 \* 2 \* 2 = 16 elements.

A tensor is a generic n-dimensional array, very similar to numpy arrays. The nice thing about using pytorch tensors in general is that you can easily put them on the gpu (as opposed to numpy arrays, which only exist on the cpu).

---

<div class="post-metadata">

**Author:** ![BroccoliFever](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/broccolifever/32/27791_2.png) [@BroccoliFever](https://discuss.pytorch.org/u/BroccoliFever)\
**Post date:** [October 19, 2017, 6:38pm UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861/3 "2017-10-19T18:38:04Z")

</div>

Awesome, thank you so much for the quick response! A question related to size then:

torch.unsqueeze(tensor, 0) adds a 1 dimensional object to the beginning of the tensor?

So tensor\_test = (2, 2, 2)  
tensor\_test.unsqueeze(0) then makes tensor\_test = (1, 2, 2, 2)?

---

<div class="post-metadata">

**Author:** ![richard](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/richard/32/1861_2.png) [@richard](https://discuss.pytorch.org/u/richard)\
**Post date:** [October 19, 2017, 6:56pm UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861/4 "2017-10-19T18:56:20Z")

</div>

Yes, torch.unsqueeze(tensor, 0) [adds a dimension](http://pytorch.org/docs/master/torch.html) to the beginning of the tensor.

---

<div class="post-metadata">

**Author:** ![junaidtariq\_tariq](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/junaidtariq_tariq/32/20137_2.png) [@junaidtariq\_tariq](https://discuss.pytorch.org/u/junaidtariq_tariq)\
**Post date:** [February 11, 2020, 1:51pm UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861/5 "2020-02-11T13:51:36Z")

</div>

Dear Richard sir,  
can we use tensors for extracting visual features as i have training and testing data in tensors now i want to extract the visual features from them so please is it possible and how can i do it?

---

<div class="post-metadata">

**Author:** ![junaidtariq\_tariq](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/junaidtariq_tariq/32/20137_2.png) [@junaidtariq\_tariq](https://discuss.pytorch.org/u/junaidtariq_tariq)\
**Post date:** [February 11, 2020, 1:53pm UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861/6 "2020-02-11T13:53:14Z")

</div>

Am working on movielens dataset of 10M and i have its data testing training in tenors form (numpy ) file can we extract visual features from the tensors.

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [February 12, 2020, 7:32am UTC](https://discuss.pytorch.org/t/what-exactly-is-a-tensor/8861/7 "2020-02-12T07:32:16Z")

</div>

Could you give an example of a visual feature, please?
