# Reinterpret a Matrix as a Vector of SVectors

**URL:** <https://discourse.julialang.org/t/reinterpret-a-matrix-as-a-vector-of-svectors/14393>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [September 1, 2018, 3:36am UTC](https://discourse.julialang.org/t/reinterpret-a-matrix-as-a-vector-of-svectors/14393 "2018-09-01T03:36:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amit112amit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amit112amit/32/10076_2.png) [@amit112amit](https://discourse.julialang.org/u/amit112amit)\
**Post date:** [September 1, 2018, 3:36am UTC](https://discourse.julialang.org/t/reinterpret-a-matrix-as-a-vector-of-svectors/14393/1 "2018-09-01T03:36:38Z")

</div>

I was trying to read the StaticArrays.jl documentation to [remap a Matrix as a Vector of SVectors](http://juliaarrays.github.io/StaticArrays.jl/latest/pages/api.html#Arrays-of-static-arrays-1) but I get an error when I try to run the example code. Can someone kindly point out the mistake?

```julia
julia> using StaticArrays

julia> function svectors(x::Matrix{Float64})
           @assert size(x,1) == 3
           reinterpret(SVector{3,Float64}, x, (size(x,2),))
       end
svectors (generic function with 1 method)

julia> rot = Matrix{Float64}(undef, 3, 10000);

julia> b = svectors(rot);
ERROR: MethodError: no method matching reinterpret(::Type{SArray{Tuple{3},Float64,1,3}}, ::Array{Float64,2}, ::Tuple{Int64})
Closest candidates are:
  reinterpret(::Type{T}, ::Base.ReshapedArray, ::Tuple{Vararg{Int64,N}} where N) where T at reshapedarray.jl:191
  reinterpret(::Type{T}, ::A<:AbstractArray{S,N}) where {T, N, S, A<:AbstractArray{S,N}} at reinterpretarray.jl:14
  reinterpret(::Type{T}, ::Any) where T at essentials.jl:370
  ...
Stacktrace:
 [1] svectors(::Array{Float64,2}) at ./REPL[2]:3
 [2] top-level scope at none:0

```

---

<div class="post-metadata">

**Author:** ![amit112amit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amit112amit/32/10076_2.png) [@amit112amit](https://discourse.julialang.org/u/amit112amit)\
**Post date:** [September 1, 2018, 4:30am UTC](https://discourse.julialang.org/t/reinterpret-a-matrix-as-a-vector-of-svectors/14393/2 "2018-09-01T04:30:50Z")

</div>

I found my answer at [Reinterpret an Array of Float64 as an Array of SVector{Float64} ? · Issue #410 · JuliaArrays/StaticArrays.jl · GitHub](https://github.com/JuliaArrays/StaticArrays.jl/issues/410).

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [September 2, 2018, 7:33pm UTC](https://discourse.julialang.org/t/reinterpret-a-matrix-as-a-vector-of-svectors/14393/3 "2018-09-02T19:33:42Z")

</div>

You can do:

`b = reinterpret(SVector{3,Float64}, rot[:]);`
