# Expand with negative shape

**URL:** <https://discuss.pytorch.org/t/expand-with-negative-shape/33061>\
**Category:** Uncategorized\
**Created:** [December 26, 2018, 4:01am UTC](https://discuss.pytorch.org/t/expand-with-negative-shape/33061 "2018-12-26T04:01:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dragen](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dragen/32/4566_2.png) [@dragen](https://discuss.pytorch.org/u/dragen)\
**Post date:** [December 26, 2018, 4:01am UTC](https://discuss.pytorch.org/t/expand-with-negative-shape/33061/1 "2018-12-26T04:01:25Z")

</div>

hi, all:  
I found torch.expand function can work with negative shape, such as [-1, 32, -1, -4], that’s weird!  
any one give some tips?

```python
In [73]: b.shape
Out[73]: torch.Size([1, 32, 1, 1])

In [72]: b.expand(-1,32,-1,-1).shape
Out[72]: torch.Size([1, 32, 1, 1])

In [71]: b.expand(-1,32,-1,-4).shape
Out[71]: torch.Size([1, 32, 1, -4])

```

---

<div class="post-metadata">

**Author:** ![smth](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/smth/32/13_2.png) [@smth](https://discuss.pytorch.org/u/smth)\
**Post date:** [December 28, 2018, 11:12pm UTC](https://discuss.pytorch.org/t/expand-with-negative-shape/33061/2 "2018-12-28T23:12:02Z")

</div>

passing -1 as size has a specific meaning and it’s documented: [https://pytorch.org/docs/stable/tensors.html#torch.Tensor.expand](https://pytorch.org/docs/stable/tensors.html#torch.Tensor.expand)

---

<div class="post-metadata">

**Author:** ![dragen](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dragen/32/4566_2.png) [@dragen](https://discuss.pytorch.org/u/dragen)\
**Post date:** [January 10, 2019, 10:28am UTC](https://discuss.pytorch.org/t/expand-with-negative-shape/33061/3 "2019-01-10T10:28:45Z")

</div>

@smth， thanks.  
However, my question, why passing `-4` do not trigger Error?
