# N dimensional array with different type

**URL:** <https://discourse.julialang.org/t/n-dimensional-array-with-different-type/102147>\
**Category:** General Usage\
**Created:** [July 27, 2023, 8:50am UTC](https://discourse.julialang.org/t/n-dimensional-array-with-different-type/102147 "2023-07-27T08:50:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey\_Novak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergey_novak/32/37716_2.png) [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Post date:** [July 27, 2023, 8:50am UTC](https://discourse.julialang.org/t/n-dimensional-array-with-different-type/102147/1 "2023-07-27T08:50:35Z")

</div>

Hello, Is it possible to create a multidimensional array that would have several types of data of the following type?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/e/3ee2d9096c431c9eedb517045c3a305f433471fd.jpeg)  
Here `id` and `i` is index. `P1`, `P2`, `time ev` type of Float64. `check ev` type of bool and another is arrays where elements is Float64.  
thank you for your help

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 27, 2023, 9:13am UTC](https://discourse.julialang.org/t/n-dimensional-array-with-different-type/102147/2 "2023-07-27T09:13:33Z")

</div>

Yes, you can have an `Array{Any, N}`:

```julia
julia> rand([1.0, true, "x"], 3, 3, 3)
3×3×3 Array{Any, 3}:
[:, :, 1] =
 true true true
     "x" true 1.0
    1.0 true 1.0

[:, :, 2] =
  "x" 1.0 "x"
 1.0 true true
  "x" "x" "x"

[:, :, 3] =
 1.0 1.0 true
 1.0 1.0 1.0
  "x" true 1.0

```

whether that’s a good idea is a different question - certainly not if you are using this in any performance critical code.

Maybe it’s an artefact of your drawing but your image looks like a table rather than a multidimensional array (maybe what people sometimes call a “long format” table), maybe a DataFrame works for you:

```julia
julia> using DataFrames

julia> DataFrame(id = [1,1,1,2,2,2], i = [1:3; 1:3], P1 = rand(6), check_ev = rand(Bool, 6))
6×4 DataFrame
 Row │ id i P1 check_ev
     │ Int64 Int64 Float64 Bool
─────┼───────────────────────────────────
   1 │ 1 1 0.761151 true
   2 │ 1 2 0.946944 false
   3 │ 1 3 0.633906 false
   4 │ 2 1 0.696095 false
   5 │ 2 2 0.87252 false
   6 │ 2 3 0.0642857 true

```

---

<div class="post-metadata">

**Author:** ![Sergey\_Novak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergey_novak/32/37716_2.png) [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Post date:** [July 27, 2023, 9:33am UTC](https://discourse.julialang.org/t/n-dimensional-array-with-different-type/102147/3 "2023-07-27T09:33:06Z")

</div>

Thank you for the suggestion. One row of the array contains elements, for example `dots u0`, which are array where elements contains vector of 3 elements.  
`dots u0` and `dots on ev` is static vector, αs just vector

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [July 27, 2023, 1:31pm UTC](https://discourse.julialang.org/t/n-dimensional-array-with-different-type/102147/4 "2023-07-27T13:31:20Z")

</div>

I use StructArray in BifurcationKit.jl for that

---

<div class="post-metadata">

**Author:** ![Sergey\_Novak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergey_novak/32/37716_2.png) [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Post date:** [July 27, 2023, 1:58pm UTC](https://discourse.julialang.org/t/n-dimensional-array-with-different-type/102147/5 "2023-07-27T13:58:10Z")

</div>

Thank you, I will try to use this package

I haven’t come up with anything better than this yet.  
Foreach value from the interval, there are 50 elements from these data structures. 1-st value from the interval corresponds to elements with indexes from 1 to 50, the second from 50 to 100 and so on.

```julia
number_points_on_side = 25
total_count_points = number_points_on_side * 2

length_p = 20
start_p = -1.700
end_p = -1.71

size_vector = length_p * total_count_points

prange = range(start_p, end_p, length = length_p)

dots_u0 = fill(Vector{Float64}(undef, 3), total_count_points)
check_events = Vector{Bool}(undef, total_count_points)
time_events = Vector{Float64}(undef, total_count_points)
dots_on_event = fill(Vector{Float64}(undef, 3), total_count_points)
αs = fill(Vector{Float64}(undef, 3), total_count_points)
norms = Vector{Float64}(undef, total_count_points)

```
