take#

swordfish.function.take()#
  • If X is a scalar (n must also be a scalar): Generates a vector containing n identical values of X.

  • If X is a vector or a tuple:

    • if n is a scalar: takes n elements from X sequentially. It can be left to right (if n > 0) or right to left (if n < 0). The result is a vector.

    • if n is a vector (must be of the same length as X): takes n[i] copies of X[i]. If n[i] <= 0, it skips X[i]. The result is a vector.

  • If X is a matrix or table:

    • if n is a scalar: It takes n rows of X sequentially, either from top to bottom (if n > 0) or bottom to top (if n < 0). The result is a matrix or table.

    • if n is a vector (must be of the same length as the number of rows in X): takes n[i] copies of the element at the i-th row of X. If n[i] <= 0, it skips the i-th row and takes no elements. The result is a matrix or table.

Parameters:
  • X (Constant) – A scalar/vector/tuple/matrix/table.

  • n (Constant) – An integer or a vector of integers.