# What is nn.Identity() used for?

**URL:** <https://discuss.pytorch.org/t/what-is-nn-identity-used-for/125457>\
**Category:** Uncategorized\
**Created:** [June 30, 2021, 10:54am UTC](https://discuss.pytorch.org/t/what-is-nn-identity-used-for/125457 "2021-06-30T10:54:07Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [June 30, 2021, 5:46pm UTC](https://discuss.pytorch.org/t/what-is-nn-identity-used-for/125457/8 "2021-06-30T17:46:33Z")

</div>

Your code snippet shows that `nn.Identity` will just return its input, but doesn’t show that it’s a view.  
If you thus manipulate the input inplace, the output of `nn.Identity` will also be changed:

```python
a = torch.arange(4.)
m = nn.Identity()
input_identity = m(a)

print(a)
> tensor([0., 1., 2., 3.])

print(input_identity)
> tensor([0., 1., 2., 3.])

# manipulate inplace
a[0] = 2.
print(a)
> tensor([2., 1., 2., 3.])

print(input_identity)
> tensor([2., 1., 2., 3.])

```

---

_[View the full topic](https://discuss.pytorch.org/t/what-is-nn-identity-used-for/125457)._
