NAME

take - shorten or extend an array along one or more axes.

SYNOPSIS

arr.take(count)
arr.take(count, axis)

DESCRIPTION

The take() method returns a new array containing a specified number of elements from the beginning or end of arr. This is similar to APL num arr and num ↑[axis] arr.

If count is positive, the first count elements are taken. If count is negative, the last abs(count) elements are taken. If abs(count) exceeds the length of the given axis the array will be extended with zeros. The count may be a vector, in which case its length must equal the rank of arr.

The axis is an axis specification. It may be a vector, in which case its length must equal the rank of arr.

RETURN VALUE

An array containing the requested elements.

ERRORS

ArgCheck if an incorrect number of arguments is provided.
ShapeCheck if the count or axis specifications are incompatible with the shape of arr.
TypeCheck if count or axis are not numeric.

EXAMPLE

    a = [10, 20, 30, 40, 50]
    a.take(2)
10 20

    a.take(-2)
40 50

    a = [3,4].iterate()
    a

    a.take([4,5])
0 1 2 0 0
3 4 5 0 0
0 0 0 0 0
0 0 0 0 0

    a.take(-2,[0,1])
 6  7
10 11

SEE ALSO

drop
subr