How to change values in GenericMatrix/Vector

PETSc stores sparse matrices, so you cant set values in arbitrary posistions without modifiying the underlying sparsitypattern. You can convert the PETScMatrix to a dense matrix, see: Transform dolfinx assemble matrix to numpy array (Note that the syntax in dolfinx is slightly different from dolfin, But the idea is the same).

You can Also see the discussion Add Matrix to Assembled Matrix