Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created February 10, 2011 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/5b33bae6bb3e28b7f815 to your computer and use it in GitHub Desktop.
Save sritchie/5b33bae6bb3e28b7f815 to your computer and use it in GitHub Desktop.
(def mat [[1 2 3 4 5]
[6 7 8 9 10]
[11 12 13 14 15]
[16 17 18 19 20]])
(defn walk-matrix
"Walks along the rows and columns of a matrix at the given window
size, returning all (window x window) snapshots."
[matrix window]
(letfn [(walk-rows [rows]
(apply map vector
(map #(partition window 1 (matrix %))
rows)))]
(reduce conj (map (comp vec walk-rows)
(partition window 1 (range (count matrix)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment