# How to slice multiple blocks efficiently from a torch tensor?

**URL:** <https://discuss.pytorch.org/t/how-to-slice-multiple-blocks-efficiently-from-a-torch-tensor/19680>\
**Category:** Uncategorized\
**Created:** [June 14, 2018, 5:07am UTC](https://discuss.pytorch.org/t/how-to-slice-multiple-blocks-efficiently-from-a-torch-tensor/19680 "2018-06-14T05:07:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![anand](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@anand](https://discuss.pytorch.org/u/anand)\
**Post date:** [June 14, 2018, 10:48am UTC](https://discuss.pytorch.org/t/how-to-slice-multiple-blocks-efficiently-from-a-torch-tensor/19680/3 "2018-06-14T10:48:55Z")

</div>

A dummy example would be :

Lets us say I have an input tensor of size [64,3,30,30] and I want to cut out slices of shape [3, 5, 5] . where 5 = ksize[0].  
Indices are of the form :

```python
indices = [
[0, 1, 2],
[1, 0, 5],
[60, 4, 1]
]

```

where each element is the index corresponding to N, w0, h0. Now I want to cut a slice of size [C, 5,5] from input using the indices. So I do it in the following way :

```python
slice = input[N, :, w0:w0+5, h0:h0+5]

```

So, the indices correspond to the top left of the slice that I want to make

---

_[View the full topic](https://discuss.pytorch.org/t/how-to-slice-multiple-blocks-efficiently-from-a-torch-tensor/19680)._
