# Index set for ITensor

**URL:** <https://itensor.discourse.group/t/index-set-for-itensor/389>\
**Category:** ITensor Julia Questions\
**Created:** [September 13, 2022, 3:09pm UTC](https://itensor.discourse.group/t/index-set-for-itensor/389 "2022-09-13T15:09:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![donion74](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/donion74/32/148_2.png) [@donion74](https://itensor.discourse.group/u/donion74)\
**Post date:** [September 13, 2022, 3:09pm UTC](https://itensor.discourse.group/t/index-set-for-itensor/389/1 "2022-09-13T15:09:54Z")

</div>

I am new to Julia and ITensor, so sorry in advance if it is a basic question: Is there a possible way to have an array of indices? My initial example is

```auto
using ITensors

function main()
    N = 4
    dims = 2*ones(Int, N)
    U = rand(dims[1], dims[2], dims[3], dims[4])

    i1 = Index(2, "i1")
    i2 = Index(2, "i2")
    i3 = Index(2, "i3")
    i4 = Index(2, "i4")

    A = ITensor(U, i1, i2, i3, i4)
    @show A

end

main()

```

and I would like to generalize for arbitrary `N`.

---

<div class="post-metadata">

**Author:** ![donion74](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/donion74/32/148_2.png) [@donion74](https://itensor.discourse.group/u/donion74)\
**Post date:** [September 15, 2022, 3:21pm UTC](https://itensor.discourse.group/t/index-set-for-itensor/389/2 "2022-09-15T15:21:47Z")

</div>

Okay, I found a solution

```auto
using ITensors

function main(; N)
    dims = 2*ones(Int, N)
    U = rand(dims...)
    j = [Index(2, "i$k") for k=1:N]

    A = ITensor(U, j...)
    @show A

end

main(N=4)

```

where `dims...` unpacks the elements of `dims`. Then I would expect `A` to have indices `i[1], [2], ..., i[N]`. The only part that (obviously) fails is `IndexSet(2, N, "i")`

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [September 18, 2022, 4:12pm UTC](https://itensor.discourse.group/t/index-set-for-itensor/389/3 "2022-09-18T16:12:03Z")

</div>

Glad you have found a good solution. Here are a few other notes:

- we have a function called `randomITensor` that you can use instead of having to first make a random Julia tensor then put it into an ITensor. In your code above you could use it like this: `A = randomITensor(j...)`
- if you are making an array of general indices with custom properties, like the tags “i1”, “i2”, that you made then your approach is the best one as it gives you the most control. However, if you specifically want to make an array of “site” indices with the tag “Site” as well as other “physics” tags like “S=1/2” or “S=1” or “Electron” or “Boson” then we have a special function for that called `siteinds` which you can use like:

```auto
s = siteinds("S=1/2",N)

```

and it will return an array of N indices with the tags “Site,S=1/2,n=1” for the first index, with “n=$n” for the nth index.
