src/manipulation

Search:
Group by:

Procs

proc newTake(arr: NDArray; axis: int; start: int; end: int): NDArray {.
    ...raises: [ValueError], tags: [], forbids: [].}

Extracts a slice along an axis (returns new array).

Parameters:

  • axis - Axis along which to slice
  • start - Starting index (inclusive)
  • end - Ending index (exclusive)

Returns: New array with extracted slice

Example:

let arr = newArange(@[4, 5], 0.0, 20.0, 1.0)
let slice = arr.newTake(0, 1, 3)  # Rows 1 and 2 (indices 1, 2)
proc newTranspose(arr: NDArray): NDArray {....raises: [ValueError], tags: [],
    forbids: [].}

Transposes array (returns new array).

Reverses the order of axes. For 2D arrays, swaps rows and columns.

Returns: New array with transposed data

Example:

let arr = newArange(@[2, 3], 0.0, 6.0, 1.0)  # 2x3 matrix
let transposed = arr.newTranspose()          # 3x2 matrix
proc reshape(arr: NDArray; newDims: openArray[int]) {....raises: [ValueError],
    tags: [], forbids: [].}

Reshapes the array in-place to new dimensions.

Total number of elements must remain the same. Use -1 for one dimension to automatically infer its size.

Parameters:

  • newDims - New shape (use -1 for auto-infer)

Example:

let arr = newArange(@[2, 6], 0.0, 12.0, 1.0)  # 2x6
arr.reshape(@[3, 4])                          # Now 3x4
arr.reshape(@[2, -1])                         # Now 2x6 (inferred)