Last active
March 11, 2019 13:27
-
-
Save RobBlackwell/d73a52422bcd4d5349d11186a9710ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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