# Row major arrays?

**URL:** <https://discourse.julialang.org/t/row-major-arrays/9225>\
**Category:** General Usage\
**Created:** [February 21, 2018, 8:20am UTC](https://discourse.julialang.org/t/row-major-arrays/9225 "2018-02-21T08:20:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [February 21, 2018, 8:20am UTC](https://discourse.julialang.org/t/row-major-arrays/9225/1 "2018-02-21T08:20:15Z")

</div>

I have to integrate with a C library that expects row-major 2D data. I could transpose/reshape an array before calling it but it seems awkward and not efficient.

What’s the best way to handle this? Maybe I could create a new array type that’s already row-major by design (unless something like this already exists)?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 21, 2018, 10:08am UTC](https://discourse.julialang.org/t/row-major-arrays/9225/2 "2018-02-21T10:08:12Z")

</div>

> [@tk3369](#):
>
> transpose/reshape an array before calling it but it seems awkward and not efficient

Transposing is generally a very cheap operation. I would do that and profile, and only think about optimizing it if it is a bottleneck.

However, if you find that you still want to do this, it is easy to create a wrapper type with row major storage. When defining methods, you can use `LinearAlgebra.Transpose` in `v0.7` and build on existing methods without copying/transposing.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [February 21, 2018, 2:20pm UTC](https://discourse.julialang.org/t/row-major-arrays/9225/3 "2018-02-21T14:20:04Z")

</div>

On master, maybe you could use [`PermuteDimsArray`](https://docs.julialang.org/en/latest/base/arrays/#Base.PermutedDimsArrays.PermutedDimsArray) / [`permutedims`](https://docs.julialang.org/en/latest/base/arrays/#Base.permutedims).
