Initialize array with dynamic length?

Is there any way to create an array with a dynamic length, similar to Python’s [0] * length construct? I’m looking for something to plug into the following:

if (g.isCalled()) g.oneHotAlleles(v) else [0]*v.nAlleles()

I’ve gone over the docs a few times without any luck – I’m sure I’m missing something very obvious…

Not missing anything, I’m afraid! We do have a function range, though, which is the only one that produces a sized array and can do what you want.

range(v.nAlleles()).map(x => 0)
1 Like

Aha, perfect, thank you!!