# Is there a matrix/array equivalent of \[a,b,c\]?

**URL:** <https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597>\
**Category:** General Usage\
**Tags:** matrices\
**Created:** [July 21, 2022, 5:37pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597 "2022-07-21T17:37:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [July 21, 2022, 5:37pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/1 "2022-07-21T17:37:42Z")

</div>

I often find myself in a situation where it is convenient to create matrices or arrays with various objects in them. For vectors, the syntax `[a,b,c]` will create a vector that holds variables a, b, and c, no matter what the types of these object are. I would like to know if there is some similar way of creating matrices or higher-dimensional arrays.

The operators `;`, `;;` and so on can be used to concatenate in various dimensions (which is useful in its own right), but this will not always work to create an array of e.g., strings or functions. For example, in julia v1.7.3 `["A" "B"; "C" "D"]`  
works, but `["A";"C";;"B";"D"]` does not (it used to in v1.7.2). If you want a matrix with arrays in it, say

```julia
[[1,2] [1,2,3] 
  [2,4,5] [7,8,9,10] ]

```

the best I’ve come up with is

```julia
reshape( [[1,2] , [2,4,5] , [1,2,3] , [7,8,9,10] ] , 2 , 2 )

```

None of this functionality is strictly necessary, but I construct objects like these often enough that I was curious if anyone knows any syntax, or possibly a macro, that would make constructing such objects more convenient.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 21, 2022, 5:49pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/3 "2022-07-21T17:49:51Z")

</div>

> [@JonasWickman](#):
>
> ```julia
> [[1,2] [1,2,3] 
> [2,4,5] [7,8,9,10] ]
> 
> ```

You need extra brackets:

```julia
julia> [[[1,2]] [[1,2,3]]
         [[2,4,5]] [[7,8,9,10]] ]
2×2 Matrix{Vector{Int64}}:
 [1, 2] [1, 2, 3]
 [2, 4, 5] [7, 8, 9, 10]

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 21, 2022, 5:54pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/4 "2022-07-21T17:54:15Z")

</div>

That does not work without those extra braces?(can’t test now).

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 21, 2022, 5:56pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/5 "2022-07-21T17:56:42Z")

</div>

> [@lmiq](#):
>
> That does not work without those extra braces?

No, it doesn’t (in 1.7.2) and the error message is logical in this case:

```julia
ERROR: ArgumentError: mismatched height in block row 1 (expected 2, got 3)

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 21, 2022, 6:04pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/6 "2022-07-21T18:04:26Z")

</div>

Indeed. I was quite wrong, a pity, I liked that ☹ , seemed consistent with the syntax for building matrices from scalars.

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [July 21, 2022, 6:22pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/7 "2022-07-21T18:22:58Z")

</div>

Perfect, thank, you!

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 21, 2022, 8:25pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/8 "2022-07-21T20:25:46Z")

</div>

> [@JonasWickman](#):
>
> but `["A";"C";;"B";"D"]` does not (it used to in v1.7.2).

This is a bug. Something that used to work in v1.7.2 should continue to work. Please file an issue:

> **[Build software better, together](https://github.com/JuliaLang/julia/issues/new)**
>
> GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [July 21, 2022, 9:31pm UTC](https://discourse.julialang.org/t/is-there-a-matrix-array-equivalent-of-a-b-c/84597/9 "2022-07-21T21:31:57Z")

</div>

Alright, issue filed:  
[https://github.com/JuliaLang/julia/issues/46133](https://github.com/JuliaLang/julia/issues/46133)
