replicate - replicate elements of an array along an axis
arr.replicate(counts)
arr.replicate(counts,
axis)
The replicate() method replicates elements of
arr along the specified axis according to the
counts. This is similar to APL key
/ arr and key
/[axis] arr
and also similar to APL
key \ arr and key.
counts can be a single integer, in which case every element along the axis is replicated that many times. Alternatively, counts can be an array of integers, specifying the replication count for each corresponding element along the axis.
If axis is not provided, it defaults to the last dimension (-1).
If a count is zero, the corresponding element is omitted from the
result. If a count is negative, the nil (default)
value for the array's base type is inserted instead of the original
element, repeated the absolute value of the count.
A new array with the specified elements replicated or omitted.
ArgCheck if the number of arguments is
incorrect
TypeCheck if counts
contains non-integer values
RangeCheck if
axis is out of the valid range of dimensions
ShapeCheck if counts is an array but its
length does not match the size of the specified axis
a = {1, 2, 3}
a.replicate(2)
1 1 2 2 3 3
a.replicate({1, 0, 2})
1 3 3
a.replicate({1, -1, 2})
1 nil 3 3