Skip to content

Instantly share code, notes, and snippets.

@Vindaar
Created April 22, 2018 17:04
Show Gist options
  • Save Vindaar/30f0e998bd5c8c79c6df37cf40d81ac0 to your computer and use it in GitHub Desktop.
Save Vindaar/30f0e998bd5c8c79c6df37cf40d81ac0 to your computer and use it in GitHub Desktop.
import sequtils
proc `[]`*[T](a: openArray[T], inds: seq[int]): seq[T] {.inline.} =
## given two openArrays, return a sequence of all elements whose indices
## are given in 'inds'
## inputs:
## a: seq[T] = the sequence from which we take values
## inds: openArray[int] = the array which contains the indices for the
## arrays, which we take from 'array'
## outputs:
## seq[T] = a sequence of all elements s.t. array[ind] in numpy indexing
result = newSeq[T](inds.len)
for i, ind in inds:
result[i] = a[ind]
let a = toSeq(0..100)
echo a[toSeq(countup(3, 50, 7))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment