I’m trying to figure out how to use view
… Consider this simple example:
x = [1, [1 2; 3 4]]
y = view(x,1)
z = view(x,2)
Here, I would have guessed that y = 1
and z = [1 2; 3 4]
, and that I could address element (2,1) of z by: z[2,1]
.
This doesn’t work, though. Instead, I have to use the syntax z[1][2,1]
.
Why?..
julia> x = [1, [1 2;3 4]]
2-element Array{Any,1}:
1
[1 2; 3 4]
julia> y = view(x,1)
0-dimensional view(::Array{Any,1}, 1) with eltype Any:
1
julia> z = view(x,2)
0-dimensional view(::Array{Any,1}, 2) with eltype Any:
[1 2; 3 4]
julia> z[2,1]
ERROR: BoundsError: attempt to access 0-dimensional view(::Array{Any,1}, 2) with eltype Any at index [2, 1]
Stacktrace:
[1] throw_boundserror(::SubArray{Any,0,Array{Any,1},Tuple{Int64},false}, ::Tuple{Int64,Int64}) at .\abstractarray.jl:484
[2] checkbounds at .\abstractarray.jl:449 [inlined]
[3] _getindex at .\abstractarray.jl:939 [inlined]
[4] getindex(::SubArray{Any,0,Array{Any,1},Tuple{Int64},false}, ::Int64, ::Int64) at .\abstractarray.jl:905
[5] top-level scope at none:0
julia> z[1][2,1]
3