# Difference between torch.tensor and torch.Tensor

**URL:** <https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786>\
**Category:** Uncategorized\
**Created:** [November 28, 2018, 3:09pm UTC](https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786 "2018-11-28T15:09:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AreTor](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/aretor/32/448_2.png) [@AreTor](https://discuss.pytorch.org/u/AreTor)\
**Post date:** [November 28, 2018, 3:09pm UTC](https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786/1 "2018-11-28T15:09:35Z")

</div>

In PyTorch docs it is written that `torch.Tensor` is an alias for `torch.FloatTensor`. This is not the case when using `torch.tensor`. For example:

```
>>> torch.Tensor([1,2,3]).dtype
torch.float32
>>> torch.tensor([1, 2, 3]).dtype
Out[32]: torch.int64
>>> torch.Tensor([True, False]).dtype
torch.float32
>>> torch.tensor([True, False]).dtype
torch.uint8

```

Isn’t this unnecessarily confusing?

---

<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:** [November 28, 2018, 8:22pm UTC](https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786/2 "2018-11-28T20:22:45Z")

</div>

`torch.tensor` infers the `dtype` automatically, while `torch.Tensor` returns a `torch.FloatTensor`.  
I would recommend to stick to `torch.tensor`, which also has arguments like `dtype`, if you would like to change the type.

---

<div class="post-metadata">

**Author:** ![AreTor](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/aretor/32/448_2.png) [@AreTor](https://discuss.pytorch.org/u/AreTor)\
**Post date:** [November 29, 2018, 8:46am UTC](https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786/3 "2018-11-29T08:46:37Z")

</div>

Agree, but my point is about the need of defining an alias `torch.FloatTensor`, which happens to be very similar in name to `torch.tensor` but has a very different behaviour and can generate confusion. Is it really needed?

---

<div class="post-metadata">

**Author:** ![lazhd](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/9dc877/32.png) [@lazhd](https://discuss.pytorch.org/u/lazhd)\
**Post date:** [February 4, 2020, 7:25pm UTC](https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786/4 "2020-02-04T19:25:49Z")

</div>

I agree, i costs me some time to find the problem caused by that.

The same here: [https://stackoverflow.com/questions/48482787/pytorch-memory-model-torch-from-numpy-vs-torch-tensor](https://stackoverflow.com/questions/48482787/pytorch-memory-model-torch-from-numpy-vs-torch-tensor)

```auto

```

arr = np.arange(10, dtype=np.float32).reshape(5, 2)

t0 = torch.Tensor(arr)  
t1 = torch.tensor(arr)  
t2 = torch.from\_numpy(arr)

arr  
t0  
t1  
t2

t2[:, 1] = 23.0

arr  
t0  
t1  
t2

```auto
arr
array([[0., 23.],
       [2., 23.],
       [4., 23.],
       [6., 23.],
       [8., 23.]], dtype=float32)

t0
tensor([[0., 23.],
        [2., 23.],
        [4., 23.],
        [6., 23.],
        [8., 23.]])

t1
tensor([[0., 1.],
        [2., 3.],
        [4., 5.],
        [6., 7.],
        [8., 9.]])

t2
tensor([[0., 23.],
        [2., 23.],
        [4., 23.],
        [6., 23.],
        [8., 23.]])

```

It’s confusing when your wife’s name is Katja, but you call her Tanja right? Unclear side effects are possible in both cases …

Searching for “torch tensor” can lead to different results containing torch.tensor and torch.Tensor results as well…

---

<div class="post-metadata">

**Author:** ![Yaroslav\_Bulatov](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/yaroslav_bulatov/32/7017_2.png) [@Yaroslav\_Bulatov](https://discuss.pytorch.org/u/Yaroslav_Bulatov)\
**Post date:** [February 4, 2020, 8:51pm UTC](https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786/5 "2020-02-04T20:51:51Z")

</div>

Agreed that it’s confusing, I get tripped up by this as well.

---

<div class="post-metadata">

**Author:** ![lijunzh](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/ac91a4/32.png) [@lijunzh](https://discuss.pytorch.org/u/lijunzh)\
**Post date:** [May 28, 2020, 1:18am UTC](https://discuss.pytorch.org/t/difference-between-torch-tensor-and-torch-tensor/30786/6 "2020-05-28T01:18:47Z")

</div>

In addition to the confusion discussed here, it also makes pylint complaining.

`a = torch.tensor([1,2,3])` results in the following error:

```auto
[pylint E1102] torch.tensor is not callable (not-callable) [E]

```

but `a=torch.Tensor([1,2,3])` works fine.
