# get ITensor slice array-wise

**URL:** <https://itensor.discourse.group/t/get-itensor-slice-array-wise/262>\
**Category:** ITensor Julia Questions\
**Created:** [July 18, 2022, 2:15pm UTC](https://itensor.discourse.group/t/get-itensor-slice-array-wise/262 "2022-07-18T14:15:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lidiastocker](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/lidiastocker/32/106_2.png) [@lidiastocker](https://itensor.discourse.group/u/lidiastocker)\
**Post date:** [July 18, 2022, 2:15pm UTC](https://itensor.discourse.group/t/get-itensor-slice-array-wise/262/1 "2022-07-18T14:15:37Z")

</div>

Hi!

From [Add support for setting slices of an ITensor by mtfishman · Pull Request #535 · ITensor/ITensors.jl · GitHub](https://github.com/ITensor/ITensors.jl/pull/535), I see that it is possible to set ITensors elements array-wise.  
I was wondering if it is possible to similarly get ITensor elements Array-wise. Something like getting B in the following:

```julia
using ITensors
i = Index(2)
j = Index(2)
k = Index(2)
l = Index(2)

A = randomITensor(i,j,k,l)
B = A[i=>1, j=>2, k=>1:end, l=>1:end] 

```

In this case, B would result in a 2x2 array or, even better, an ITensor with indices (i,j).

I am using Julia v1.7.0 and ITensors v0.3.18

Thanks in advance for any reply!

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [July 19, 2022, 1:56pm UTC](https://itensor.discourse.group/t/get-itensor-slice-array-wise/262/2 "2022-07-19T13:56:08Z")

</div>

The closest thing we have right now to do that kind of slicing is:

```julia
julia> using ITensors

julia> i, j, k, l = Index.((2, 2, 2, 2))
((dim=2|id=477), (dim=2|id=714), (dim=2|id=447), (dim=2|id=498))

julia> A = randomITensor(i, j, k, l)
ITensor ord=4 (dim=2|id=477) (dim=2|id=714) (dim=2|id=447) (dim=2|id=498)
NDTensors.Dense{Float64, Vector{Float64}}

julia> B = A * onehot(i => 1, j => 2)
ITensor ord=2 (dim=2|id=447) (dim=2|id=498)
NDTensors.Dense{Float64, Vector{Float64}}

```

---

<div class="post-metadata">

**Author:** ![lidiastocker](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/lidiastocker/32/106_2.png) [@lidiastocker](https://itensor.discourse.group/u/lidiastocker)\
**Post date:** [July 19, 2022, 2:19pm UTC](https://itensor.discourse.group/t/get-itensor-slice-array-wise/262/3 "2022-07-19T14:19:26Z")

</div>

thank you very much for the quick reply, this is exactly what I needed!
