Getindex with default value

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).

It’s the same.

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

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

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

1 Like