# Diagonal 3D array

**URL:** <https://discourse.julialang.org/t/diagonal-3d-array/1038>\
**Category:** General Usage\
**Created:** [December 19, 2016, 10:59am UTC](https://discourse.julialang.org/t/diagonal-3d-array/1038 "2016-12-19T10:59:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [December 19, 2016, 10:59am UTC](https://discourse.julialang.org/t/diagonal-3d-array/1038/1 "2016-12-19T10:59:43Z")

</div>

I’m working on an expression language for handling (sometimes) sparse diagonal arrays. In index notation, these expressions look something like:

```
X[i,j], where i == j
X[i,j,k], where i == k
X[i,j,k], where j == k

```

etc. That is, `X` is a matrix with only main diagonal having non-zero elements, e.g.:

```
X = 0.089022 0 0      
         0 0.0622766 0      
         0 0 0.374836

```

In vector notation, first expression is equivalent to `Diagonal(X)`, but is there a way or array type to represent the same idea for 3D, 4D, etc. arrays?

Note, that I’m mostly interested in symbolic representation of these arrays for further transformations, but efficient (i.e. sparse) representation for them is also nice to have.
