""" | |
column_vectors(A) | |
Given a two dimensional array `A` of size `m` x `n`, return an array | |
of `n` vectors being the columns in `A`. Each vector is of length `m`. | |
""" | |
function column_vectors(A) | |
m,n = size(A) | |
[A[:,i] for i in 1:n] | |
end | |
function row_vectors(A) | |
m,n = size(A) | |
[A[i,:] for i in 1:m] | |
end | |
""" | |
skipnan(itr) | |
Return a copy of itr with NaNs removed. | |
""" | |
skipnan(itr) = filter(!isnan, itr) | |
""" | |
findintervals(A, n=5) | |
Given a sorted array `A`, find the pairs of indices that split `A` | |
into intervals of size `n`. | |
""" | |
function findintervals(A, n=5) | |
a = findfirst.(A .>= x for x in n:n:A[end]) | |
zip([1;a[1:end-1].+1], a) | |
end | |
""" | |
mapintervals(f, A, intervals) | |
Maps a function `f` over `intervals` in `A`. | |
""" | |
function mapintervals(f, A, intervals) | |
[f(a[x:y]) for (x,y) in intervals] | |
end | |
## contains is replaced by occursin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment