# How to create a zero-based array?

**URL:** <https://discourse.julialang.org/t/how-to-create-a-zero-based-array/91127>\
**Category:** General Usage\
**Created:** [December 2, 2022, 6:14am UTC](https://discourse.julialang.org/t/how-to-create-a-zero-based-array/91127 "2022-12-02T06:14:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathaniel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathaniel/32/37854_2.png) [@Nathaniel](https://discourse.julialang.org/u/Nathaniel)\
**Post date:** [December 2, 2022, 6:14am UTC](https://discourse.julialang.org/t/how-to-create-a-zero-based-array/91127/1 "2022-12-02T06:14:10Z")

</div>

I’d like to create a multidimensional array whose indexes start at 0 instead of 1. I know that this is possible, but I can’t seem to find a simple example of how.

[This page of the official documentation](https://docs.julialang.org/en/v1/devdocs/offset-arrays/) starts out promising, explaining that Julia supports arbitrary indexing, but then it continues with “The purpose of this page is to address the question, ‘what do I have to do to support such arrays in my own code?’”. The rest of it is technical details on how to make code compatible with arbitrary-indexed arrays, but it doesn’t seem to give an example of how to create such an array from the user end.

On the other hand, the [page on array indexing](https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing) doesn’t mention it at all as far as I can tell.

So, what’s a simple example of how to create, say, a `10x10` matrix `A` whose entries run from `A[0,0]` to `A[9,9]` instead of `A[1,1]` to `A[10,10]`?

P.S. let’s avoid discussing opinions about the topic if possible!

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [December 2, 2022, 6:32am UTC](https://discourse.julialang.org/t/how-to-create-a-zero-based-array/91127/2 "2022-12-02T06:32:52Z")

</div>

```julia
julia> using OffsetArrays

julia> N = 10
10

julia> ℱ = OffsetArrays.Origin(0)([exp(-2π*im*m*n/N) for m=0:N-1, n=0:N-1])
10×10 OffsetArray(::Matrix{ComplexF64}, 0:9, 0:9) with eltype ComplexF64 with indices 0:9×0:9:
 1.0-0.0im 1.0-0.0im 1.0-0.0im … 1.0-0.0im
 1.0-0.0im 0.809017-0.587785im 0.309017-0.951057im 0.809017+0.587785im
 1.0-0.0im 0.309017-0.951057im -0.809017-0.587785im 0.309017+0.951057im
 1.0-0.0im -0.309017-0.951057im -0.809017+0.587785im -0.309017+0.951057im
 1.0-0.0im -0.809017-0.587785im 0.309017+0.951057im -0.809017+0.587785im
 1.0-0.0im -1.0-1.22465e-16im 1.0+2.44929e-16im … -1.0-1.10218e-15im
 1.0-0.0im -0.809017+0.587785im 0.309017-0.951057im -0.809017-0.587785im
 1.0-0.0im -0.309017+0.951057im -0.809017-0.587785im -0.309017-0.951057im
 1.0-0.0im 0.309017+0.951057im -0.809017+0.587785im 0.309017-0.951057im
 1.0-0.0im 0.809017+0.587785im 0.309017+0.951057im 0.809017-0.587785im

julia> ℱ[0,0]
1.0 - 0.0im

```
