Nicholas Tomlin
Nicholas Tomlin

Reputation: 195

Indexing into multidimensional array

In Julia, is it possible to index into one array with another? I'm looking for something like this:

a = Array{Int8}(undef, 3, 3, 3)
b = [1,2,3]

a[b] = 12

But so far the only solution I can find is a[b[1], b[2], b[3]] = 12. Is there a cleaner solution?

Upvotes: 4

Views: 120

Answers (1)

hckr
hckr

Reputation: 5583

Here is the clean way of doing it. You use the ... for passing a tuple as function arguments, as well. This is known as splatting.

a[b...]

Upvotes: 4

Related Questions