# Command: Take

NEST HelpDesk | Command Index | NEST Quick Reference

Name:

    Take - extract element sequences from a container

Synopsis:

      array  n Take	 return the first n elements
      array -n Take	 return the last n elements
      array [n1 n2] Take	 return elements n1 through n2
      array [n1 n2 s] Take	 return elements n1 through n2 in steps of s
      array [[seq1]...[seqn]] Take   return a nested list in which elements
      specified by seqi are taken at level i in list.

      Operations are the same on strings.
      The implementation of Take uses the command container to abstract
      the container type.

      Note that Take handles indices ranging from -N to N where
      N is the length of the original container and asking for index 0
      will return an empty array.

      If the specified indices do not exist in the container, Take throws a RangeCheck error.

      If n2 < n1, Take returns an empty container.

Examples:

      [4 9 -7 3 2 11] 2 Take   --> [4 9]
      [4 9 -7 3 2 11] -2 Take   --> [2 11]
      [1 2 3 4 5] [-2] Take	 --> 4
      [1 2 3 4 5] [1 -2] Take   --> [1 2 3 4]
      [1 2 3 4 5] [1 -2 2] Take --> [1 3]
      [1 2 3 4 5] [1 -1 2] Take --> [1 3 5]
      % [1 2 3 4 5] [1 6] Take   --> [Error]: RangeCheck
      (HAL) {1 add} Map	 --> (IBM)
      (HAL) 2 Take	 --> (HA)
      (HAL) -2 Take	 --> (AL)
      (HALLO) [-2] Take	 --> 76
      (HALLO) [1 -2] Take   --> (HALL)
      (HALLO) [1 -2 2] Take --> (HL)
      (HALLO) [1 -1 2] Take --> (HLO)

Bugs:

      The scheme for a list of sequences is not fully consistent with Mathematica.
      See Drop for a more advanced implementation.

References:

      [1] The Mathematica Book V4.0 "Take"

Author:

    Diesmann

SeeAlso:

- Drop
- Part
- MathematicaToSliIndex
- getinterval
- get

Source:

    /opt/conda/conda-bld/nest_1512418773968/work/nest-2.14.0/lib/sli/mathematica.sli

NEST HelpDesk | Command Index | NEST Quick Reference

© 2004 The NEST Initiative