# Should I use a matrix or vector of vectors?

**URL:** <https://discourse.julialang.org/t/should-i-use-a-matrix-or-vector-of-vectors/99470>\
**Category:** New to Julia\
**Created:** [May 26, 2023, 10:07pm UTC](https://discourse.julialang.org/t/should-i-use-a-matrix-or-vector-of-vectors/99470 "2023-05-26T22:07:37Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![sadish-d](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sadish-d/32/48058_2.png) [@sadish-d](https://discourse.julialang.org/u/sadish-d)\
**Post date:** [May 27, 2023, 1:13pm UTC](https://discourse.julialang.org/t/should-i-use-a-matrix-or-vector-of-vectors/99470/12 "2023-05-27T13:13:43Z")

</div>

I found some discussion here about checking contiguity of a vector’s elements:

> [@Checking if a vector of structs is contiguous in memory](https://discourse.julialang.org/t/checking-if-a-vector-of-structs-is-contiguous-in-memory/2759):
>
> Hi, So I have an vector of tuples of floats, i.e.: Array{Tuple{Float64,Float64},1}(). I know that tuples are immutables and so theoretically this array should be contiguous in memory and there should be no pointers in the vector or the tuples. Is this true? And more generally is there a way that I can check whether is type in contiguous in memory or whether it contains pointers in it? Thanks.

I might very well implement the inner-vectors as structs, so I think things get complicated. So we can rest the discussion here. Thanks for your help.

As a summary (so I can mark this post as a solution), here are the recommended options:

1. vector-of-vectors:

- work well with broadcasting
- inner vectors might not be contiguous in memory
- might be preferable than the next option (see 2 below) if the inner vectors need to be read in arbitrary order

1. matrices with inner-vectors as columns:

- would work if the inner-vectors have the same length
- preferable since matrix columns are contiguous in memory (if that’s important)
- columns should be retrieved as views so as not to copy data

---

_[View the full topic](https://discourse.julialang.org/t/should-i-use-a-matrix-or-vector-of-vectors/99470)._
