# Cannot set a non-diagonal index in a Hermitian matrix

**URL:** https://discourse.julialang.org/t/cannot-set-a-non-diagonal-index-in-a-hermitian-matrix/9348
**Category:** General Usage
**Tags:** linearalgebra
**Created:** [February 26, 2018, 7:06pm UTC](https://discourse.julialang.org/t/cannot-set-a-non-diagonal-index-in-a-hermitian-matrix/9348 "2018-02-26T19:06:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [February 26, 2018, 7:06pm UTC](https://discourse.julialang.org/t/cannot-set-a-non-diagonal-index-in-a-hermitian-matrix/9348/1 "2018-02-26T19:06:19Z")

</div>

Is there a way to set a non-diagonal entry in a Hermitian matrix? For example, if I set `H[i,j]`, I’d expect the implementation to automatically set `H[j,i]` as well, to maintain hermiticity.

---

<div class="post-metadata">

### Author: ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)
#### Post date: [February 26, 2018, 7:43pm UTC](https://discourse.julialang.org/t/cannot-set-a-non-diagonal-index-in-a-hermitian-matrix/9348/2 "2018-02-26T19:43:07Z")

</div>

You can do it yourself by changing the underlying array. Note that the displayed matrix only displays the upper or lower triangle of the underlying array ([depending on how you constructed the Hermitian matrix](https://docs.julialang.org/en/stable/stdlib/linalg/#Base.LinAlg.Hermitian)), and so you only need to modify the value in the active triangle.

```julia
julia> H = Hermitian(rand(4,4))
4×4 Hermitian{Float64,Array{Float64,2}}:
 0.763319 0.610173 0.726294 0.299563
 0.610173 0.459978 0.0105791 0.995507
 0.726294 0.0105791 0.00780527 0.418519
 0.299563 0.995507 0.418519 0.769661

julia> H.data[2,3] = 1
1

julia> H
4×4 Hermitian{Float64,Array{Float64,2}}:
 0.763319 0.610173 0.726294 0.299563
 0.610173 0.459978 1.0 0.995507
 0.726294 1.0 0.00780527 0.418519
 0.299563 0.995507 0.418519 0.769661

julia> H.data
4×4 Array{Float64,2}:
 0.763319 0.610173 0.726294 0.299563
 0.456174 0.459978 1.0 0.995507
 0.554286 0.987036 0.00780527 0.418519
 0.171225 0.227228 0.055119 0.769661

```
