# Indexes and multidimensional arrays

**URL:** <https://discourse.julialang.org/t/indexes-and-multidimensional-arrays/58200>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 29, 2021, 11:44pm UTC](https://discourse.julialang.org/t/indexes-and-multidimensional-arrays/58200 "2021-03-29T23:44:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![spirit1jkm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/spirit1jkm/32/19227_2.png) [@spirit1jkm](https://discourse.julialang.org/u/spirit1jkm)\
**Post date:** [March 29, 2021, 11:44pm UTC](https://discourse.julialang.org/t/indexes-and-multidimensional-arrays/58200/1 "2021-03-29T23:44:13Z")

</div>

New to code and to Julia. I want to return the value at a specific index in a multidimensional array. I have been watching the Julia Zero to Hero video on YouTube and reading the Julia documentation. Based on that, given a multidimensional array created with  
lockscreen = [[‘A’, ‘B’, ‘C’],[‘D’, ‘E’, ‘F’], [‘G’,‘H’, ‘I’]]  
I expected that lockscreen[2,1] would return ‘D’, but it returned the whole row:

julia\> lockscreen = [[‘A’, ‘B’, ‘C’],[‘D’, ‘E’, ‘F’], [‘G’,‘H’, ‘I’]]  
3-element Array{Array{Char,1},1}:  
[‘A’, ‘B’, ‘C’]  
[‘D’, ‘E’, ‘F’]  
[‘G’, ‘H’, ‘I’]

julia\> lockscreen[2,1]3-element Array{Char,1}:  
‘D’: ASCII/Unicode U+0044 (category Lu: Letter, uppercase)  
‘E’: ASCII/Unicode U+0045 (category Lu: Letter, uppercase)  
‘F’: ASCII/Unicode U+0046 (category Lu: Letter, uppercase)

I tried it with a different multidimensional array using numbers  
julia\> testmatrix = [[1,2,3],[4,5,6],[7,8,9]]  
3-element Array{Array{Int64,1},1}:  
[1, 2, 3]  
[4, 5, 6]  
[7, 8, 9]

julia\> testmatrix[2,1]  
3-element Array{Int64,1}:  
4  
5  
6

How do I just return the single value of the value located at index 2,1 in the matrix?

I also do not understand the error when I ask for value at index 3,3

julia\> testmatrix = [[1,2,3],[4,5,6],[7,8,9]]3-element Array{Array{Int64,1},1}:  
[1, 2, 3]  
[4, 5, 6]  
[7, 8, 9]

julia\> testmatrix[3,3]  
ERROR: BoundsError: attempt to access 3-element Array{Array{Int64,1},1} at index [3, 3]  
Stacktrace:  
[1] getindex(::Array{Array{Int64,1},1}, ::Int64, ::Int64) at ./array.jl:810  
[2] top-level scope at REPL[26]:1

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 30, 2021, 12:37am UTC](https://discourse.julialang.org/t/indexes-and-multidimensional-arrays/58200/2 "2021-03-30T00:37:47Z")

</div>

> [@spirit1jkm](#):
>
> I tried it with a different multidimensional array using numbers  
> julia\> testmatrix = [[1,2,3],[4,5,6],[7,8,9]]

That’s not a multidimensional array. It’s a 1d array of 1d arrays, which (unlike in Python) is not the same thing.

You want e.g. `[1 2 3; 4 5 6; 7 8 9]`

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [March 30, 2021, 3:38am UTC](https://discourse.julialang.org/t/indexes-and-multidimensional-arrays/58200/3 "2021-03-30T03:38:42Z")

</div>

Welcome! @stevengj has the right answer here. Just want to add that you can make your posts nicer and easier to help with by following the steps outlined here: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [March 30, 2021, 8:52pm UTC](https://discourse.julialang.org/t/indexes-and-multidimensional-arrays/58200/4 "2021-03-30T20:52:59Z")

</div>

Have a look here: [2 - Data types - Julia language: a concise tutorial](https://syl1.gitbook.io/julia-language-a-concise-tutorial/language-core/data-types#multidimensional-and-nested-arrays)

When you write a post here, you can embed code using three “reverse quotes” (or whatever they are called…) “```”

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [March 31, 2021, 8:28am UTC](https://discourse.julialang.org/t/indexes-and-multidimensional-arrays/58200/5 "2021-03-31T08:28:54Z")

</div>

> [@spirit1jkm](#):
>
> lockscreen = [[‘A’, ‘B’, ‘C’],[‘D’, ‘E’, ‘F’], [‘G’,‘H’, ‘I’]]

Also, you can do:

```julia
julia> lockscreen[2][1]
'D': ASCII/Unicode U+0044 (category Lu: Letter, uppercase)

```
