# Indexes and multidimensional arrays

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

1 Like

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]`

6 Likes

``````julia> lockscreen[2][1]