Getindex with default value

question

#1

There is a nice convenience method of get, that allows to handle out of bounds access with a default value.

julia> get([1,2],1000,"my default value")
"my default value"

Is there something analog for multidimensional indexing? For instance I want to to access a 3x5 matrix and get back NaN at index (100,200).


#2

It’s the same.

julia> get(rand(3, 5), (100, 200), NaN)
NaN

#3

Dang, I tried get(rand(3,5), CartesianIndex(100,200), NaN) and it did not work :D.


#4

It’s probably an oversight that it doesn’t work. Worth filing an issue about, or even a pull request.


#5