# Long vs Flatten

**URL:** <https://discuss.pytorch.org/t/long-vs-flatten/72184>\
**Category:** Uncategorized\
**Created:** [March 5, 2020, 7:33pm UTC](https://discuss.pytorch.org/t/long-vs-flatten/72184 "2020-03-05T19:33:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dachosen1](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/d/47e85d/32.png) [@dachosen1](https://discuss.pytorch.org/u/dachosen1)\
**Post date:** [March 5, 2020, 7:33pm UTC](https://discuss.pytorch.org/t/long-vs-flatten/72184/1 "2020-03-05T19:33:23Z")

</div>

I’m evaluating the performance of my model using the cross-entropy loss. I flatten my target variables using flatten construct from torch to get a [x,1] tensor object. I received a Runtime Error: Expected object of scalar type Long by got a scalar type Int for argument #2 target.

I was able to fix using the scalar type long. I still don’t understand why it didn’t work since borth functions produce the same shape? What’s the difference betweeen Long vs Flatten in Pytorch?

---

<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:** [March 5, 2020, 8:00pm UTC](https://discuss.pytorch.org/t/long-vs-flatten/72184/2 "2020-03-05T20:00:35Z")

</div>

Calling `tensor.long()` returns a `LongTensor`, which is the tensor data type.  
The error message explains, that you are passing an `IntTensor` instead of a `LongTensor`.  
The data type is independent of the tensor shape.

---

<div class="post-metadata">

**Author:** ![dachosen1](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/d/47e85d/32.png) [@dachosen1](https://discuss.pytorch.org/u/dachosen1)\
**Post date:** [March 5, 2020, 9:10pm UTC](https://discuss.pytorch.org/t/long-vs-flatten/72184/3 "2020-03-05T21:10:11Z")

</div>

I was able to address the error, but didn’t know the difference between the two types. From what I was able to gather a `LongTensor` is a 64bit integer vs an `IntTensor `is a 32bit integer. Did i miss anything else?

---

<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:** [March 6, 2020, 12:19am UTC](https://discuss.pytorch.org/t/long-vs-flatten/72184/4 "2020-03-06T00:19:25Z")

</div>

Your understanding is correct. 🙂
