Fork me on GitHub
#core-matrix
<
2017-05-26
>
andrea.crotti09:05:18

is there a way to fill in a submatrix with a value?

andrea.crotti09:05:52

I can easily fetch a submatrix but can't find the right function to generate a new matrix with submatrix filled with the value I want

mikera10:05:34

Some implementations support mutable submatrices

mikera10:05:41

e.g. with vectorz-clj

mikera10:05:42

(let [m (new-array :vectorz [3 3])] (fill! (submatrix m [[1 2] [1 2]]) 7) m) #vectorz/matrix [[0.0,0.0,0.0], [0.0,7.0,7.0], [0.0,7.0,7.0]]

mikera10:05:52

That's probably the most efficient. Otherwise you can use set-selection e.g.

mikera10:05:53

(let [m (new-array :vectorz [3 3])] (set-selection m [1 2] [1 2] 7)) #vectorz/matrix [[0.0,0.0,0.0], [0.0,7.0,7.0], [0.0,7.0,7.0]]

andrea.crotti10:05:28

seems to work in the same way also without the :vectorz @mikera

andrea.crotti10:05:28

is that the default maybe?

mikera10:05:45

set-selection should be fine with any implementation

mikera10:05:53

The fill! method requires a mutable implementation

andrea.crotti10:05:08

set-selection would be good but it only returns the submatrix changed

andrea.crotti10:05:19

not a whole new matrix with the content changed

mikera10:05:31

Hmmm it should return the whole new matrix

mikera10:05:39

You have a simple example?

andrea.crotti10:05:14

ah no sorry my bad

andrea.crotti10:05:13

yeah that seems perfect

mikera10:05:31

Cool glad it works for you!

mikera10:05:31

I've been meaning to get something like specter working with core.matrix, this would be a more general tool that would be very useful for examples like this

octahedrion12:05:31

i may have asked this before but is there a way to get the vector of indices of the max element of a matrix ?