Message Boards Message Boards

[✓] Add plus 1 to the {i_,i_} elements in a list?


I have a list of lists of numbers, for example:

{{1,1,1,1}, {1,1,1,1},{1,1,1,1},{1,1,1,1}} 

The length of the list is the same length of each sublist. What I want to achieve is to add plus 1 to the {i,i} elements without using For cycle. Given the list above as an input, I need a result like this:

{{2,1,1,1}, {1,2,1,1},{1,1,2,1},{1,1,1,2}}
POSTED BY: Ana Reyna
1 month ago

It sounds like you have a square matrix, and you want to add IdentityMatrix@Length[matrix] to it.

POSTED BY: Szabolcs Horvát
1 month ago

Group Abstract Group Abstract