# Why are dimensions transposed in \`arrayFromVolume\`?

**URL:** <https://discourse.slicer.org/t/why-are-dimensions-transposed-in-arrayfromvolume/21873>\
**Category:** Development\
**Tags:** python, volume\
**Created:** [February 9, 2022, 5:31pm UTC](https://discourse.slicer.org/t/why-are-dimensions-transposed-in-arrayfromvolume/21873 "2022-02-09T17:31:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [February 9, 2022, 5:31pm UTC](https://discourse.slicer.org/t/why-are-dimensions-transposed-in-arrayfromvolume/21873/1 "2022-02-09T17:31:46Z")

</div>

In the function `slicer.util.arrayFromVolume`, it looks like the IJK directions get permuted, [see the `reversed` here](https://github.com/Slicer/Slicer/blob/fab4ec043672efc3434ae29fea498979b9ae7b17/Base/Python/slicer/util.py#L1469). Can anyone explain the reason for this?

If I understand correctly, this permutes `I,J,K` to `K,J,I`, so for example the 0th dimension of the array returned by `arrayFromVolume` ends up corresponding to the `K` direction. That seems weird, so maybe I am missing something here…

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [February 9, 2022, 6:50pm UTC](https://discourse.slicer.org/t/why-are-dimensions-transposed-in-arrayfromvolume/21873/2 "2022-02-09T18:50:55Z")

</div>

Take a look at this comment

> **[Very confused about imdata matrix index order](https://discourse.vtk.org/t/very-confused-about-imdata-matrix-index-order/6608/2?u=lassoan)**
>
> For an array (or matrix), the indexing is \[row, col\] for two dimensions, or \[slice, row, col\] for three dimensions. Consider the following code, where a\[1,0\] means row=1, col=0: \>\>\> import numpy as np \>\>\> np.array(\[\[1,2\],\[3,4\]\])...

linked from this ITK thread

> **[Image index ordering in Python API](https://discourse.itk.org/t/image-index-ordering-in-python-api/4496)**
>
> I know this topic has been discussed before, and maybe all decisions have been made and too much legacy exists anyway already… Still, I find it strange to have this numpy array like view of an ITK image with inverted index ordering: coming from...

---

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [February 9, 2022, 6:59pm UTC](https://discourse.slicer.org/t/why-are-dimensions-transposed-in-arrayfromvolume/21873/3 "2022-02-09T18:59:30Z")

</div>

Thank you, I suppose this explains the reasoning. `K,J,I` order is trying to be like (slice, row, column).
