-
Notifications
You must be signed in to change notification settings - Fork 111
Views
Ritchie Cai edited this page Sep 29, 2015
·
5 revisions
core.matrix
supports the concept of views as a tool for inspecting and modifying portions of larger arrays. Many core.matrix
functions that return a subset of a larger array will return a view.
Mutable view of a single row/column
(ns test.core
(:require [clojure.core.matrix :as mat]))
(def m (mat/new-matrix 3 4))
;; #vectorz/matrix [[0.0,0.0,0.0,0.0],
;; [0.0,0.0,0.0,0.0],
;; [0.0,0.0,0.0,0.0]]
(mat/assign! (mat/get-row m 0) (mat/array [1 2 3 4]))
;; #vectorz/matrix [[1.0,2.0,3.0,4.0],
;; [0.0,0.0,0.0,0.0],
;; [0.0,0.0,0.0,0.0]]
(mat/assign! (mat/get-column m 2) (mat/array [5 6 7]))
;; #vectorz/matrix [[1.0,2.0,5.0,4.0],
;; [0.0,0.0,6.0,0.0],
;; [0.0,0.0,7.0,0.0]]