I work with Elixir Matrex (https://hexdocs.pm/matrex/Matrex.html) and want to update or set all diagonals elements to zeros (and later to ones).
I tried:
matrix_size = 5
randommatrix = Matrex.random(matrix_size)
for index_i <- 1 .. matrix_size, do: randommatrix = Matrex.update(randommatrix, index_i, index_i, fn a -> 0 end)
#subsequent work with matrix that has all diagonal elements zero
#...
This approach updates randommatrix only "inside" comprehension and the subsequent code sees the randommatrix unchanged.
I think that I can do what I need through recursive function, however, is there any other efficient method (minimal computer time)? Thanks