Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create three (or higher) dimensional array with Julia

Tags:

arrays

julia

In Julia, the ; may be used to create a two-dimensional array.

julia> [1 2; 3 4]
2x2 Array{Int64,2}:
 1  2
 3  4

Is it possible to use a similar syntax to create a three-dimensional (or higher-dimensional) array? The following works, but I am unsure as to whether or not there is a cleaner, better way.

julia> reshape(collect(1:8), 2, 2, 2)
2x2x2 Array{Int64,3}:
[:, :, 1] =
 1  3
 2  4

[:, :, 2] =
 5  7
 6  8
like image 494
2Cubed Avatar asked Dec 05 '22 00:12

2Cubed


1 Answers

I suppose the cleanest manual syntax is via the cat command, e.g.:

cat(3, [1 2 ;3 4], [5 6 ; 7 8]);   % concatenate along the 3rd dimension
like image 162
Tasos Papastylianou Avatar answered Jan 23 '23 08:01

Tasos Papastylianou