Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have Matrix of vectors in julia?

Tags:

julia

Can we form a julia matrix whose elements are vectors? I have tried the following but it only formed a matrix of Int.

julia> [[1, 2] [2, 3]; [4, 5] [3, 5]]
4×2 Matrix{Int64}:
1  2
2  3
4  3
5  5

But I wanted [1, 2] to be the first element not 1. Is it possible?

like image 861
Ritu Lahkar Avatar asked Nov 14 '25 09:11

Ritu Lahkar


1 Answers

Here is one way to do it:

julia> [[[1, 2]] [[2, 3]]; [[4, 5]] [[3, 5]]]
2×2 Matrix{Vector{Int64}}:
 [1, 2]  [2, 3]
 [4, 5]  [3, 5]

another would be:

julia> reshape([[1, 2], [4, 5], [2, 3], [3, 5]], 2, 2)
2×2 Matrix{Vector{Int64}}:
 [1, 2]  [2, 3]
 [4, 5]  [3, 5]

but maybe there is some better solution.

like image 141
Bogumił Kamiński Avatar answered Nov 17 '25 08:11

Bogumił Kamiński



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!