# How do I extract number of dimensions and type from a StaticArray?

**URL:** https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497
**Category:** General Usage
**Created:** [February 12, 2023, 9:01am UTC](https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497 "2023-02-12T09:01:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [February 12, 2023, 9:01am UTC](https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497/1 "2023-02-12T09:01:57Z")

</div>

Hello!

Suppose I have:

```julia
    n, d = 100, 2
    p = rand(SVector{d,Float64},n)

 p = rand(SVector{d,Float64},n)
100-element Vector{SVector{2, Float64}}:
 [0.45095181425482966, 0.07762277325569156]
 [0.08059534744395058, 0.6894885967075672]
 [0.17420764849307047, 0.5389305800109263]
 [0.49059524232908114, 0.8173513178012474]
 [0.10571769568776879, 0.10357908367697921]
 [0.9792467310066209, 0.23057688418253763]
 [0.9847249018638312, 0.217772010510753]
 [0.0840194679091536, 0.504223015371956]
 [0.01633520205319361, 0.9021979319615324]
 ⋮
 [0.06984810450766477, 0.9596269881836494]
 [0.31785593598143047, 0.9321562497383631]
 [0.6830008727269754, 0.2723801423965435]
 [0.10025068872213305, 0.49455865902837015]
 [0.5442057537990393, 0.7884480165567407]
 [0.4287597478514289, 0.5612363821439627]
 [0.46923631245452835, 0.4326449125447476]
 [0.05712658935227466, 0.8437525317817943]

```

How would I go about pulling out **from the type definition** , SVector{2, Float64}, that dimensions = 2 and type = Float64?

Thank you

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [February 12, 2023, 9:16am UTC](https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497/2 "2023-02-12T09:16:12Z")

</div>

```julia
julia> getspecs1(::SVector{d,T}) where {d,T} = (dimensions=d, type=T)
getspecs1 (generic function with 1 method)

julia> getspecs1(p[1])
(dimensions = 2, type = Float64)

julia> getspecs2(::Type{SVector{d,T}}) where {d,T} = (dimensions=d, type=T)
getspecs2 (generic function with 1 method)

julia> getspecs2(SVector{2,Float64})
(dimensions = 2, type = Float64)

```

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [February 12, 2023, 9:22am UTC](https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497/3 "2023-02-12T09:22:27Z")

</div>

Perfect, I was not aware one could infer like that 🙂 Cool!

And here is how to call it for my case;

```julia
getspecs2(eltype(p))
(dimensions = 2, type = Float64)

```

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [February 12, 2023, 9:25am UTC](https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497/4 "2023-02-12T09:25:48Z")

</div>

You can also do this (and variants thereof):

```julia
julia> getspecs3(::Vector{SVector{d,T}}) where {d,T} = (dimensions=d, type=T)
getspecs3 (generic function with 1 method)

julia> getspecs3(p)
(dimensions = 2, type = Float64)

```
