# Converting 1×10 Array{Int64,2} to 10x1 Array{Int64,2}

**URL:** <https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316>\
**Category:** New to Julia\
**Created:** [April 15, 2021, 8:21am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316 "2021-04-15T08:21:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [April 15, 2021, 8:21am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/1 "2021-04-15T08:21:16Z")

</div>

```
A = [0 0 0 0 0 0 0 0 0 0]

```

is a 1×10 Array{Int64,2}.

Why is A’ not a 10x1 Array{Int64,2} but a 10×1 Adjoint{Int64,Array{Int64,2}}?

Or, how do I convert A to a 10x1 Array{Int64,2}?

---

<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:** [April 15, 2021, 8:34am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/2 "2021-04-15T08:34:42Z")

</div>

Because the adjoint is more efficient, you can `collect` it if you want to:

```julia
julia> a = collect(1:10)
10-element Vector{Int64}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

julia> a'
1×10 adjoint(::Vector{Int64}) with eltype Int64:
 1 2 3 4 5 6 7 8 9 10

julia> collect(a')
1×10 Matrix{Int64}:
 1 2 3 4 5 6 7 8 9 10

julia> using BenchmarkTools

julia> @btime $a';
  1.200 ns (0 allocations: 0 bytes)

julia> @btime collect($a');
  44.489 ns (1 allocation: 160 bytes)

```

But most of the time that shouldn’t actually be necessary as you can work with the adjoint.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [April 15, 2021, 8:35am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/3 "2021-04-15T08:35:55Z")

</div>

> [@Nash](#):
>
> `A = [0 0 0 0 0 0 0 0 0 0]`

you may be happier starting with (note the commas)  
` A = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]`

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 15, 2021, 8:51am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/4 "2021-04-15T08:51:15Z")

</div>

Or just: `transpose(A)`

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 15, 2021, 9:00am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/5 "2021-04-15T09:00:09Z")

</div>

Note that `'` will also transpose complex values - it’s only a syntax shortcut for conjugate transpose after all. `transpose(x)` itself is recursive, so if you only want to change the dimensionality on the top level, use `permutedims` instead.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [April 15, 2021, 9:57am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/6 "2021-04-15T09:57:38Z")

</div>

First of all, you can just use the adjoint, `a'`, as is, in most cases you don’t need to `collect` it. If you absolutely need a 10x1 `Array`, then `reshape(a, :, 1)` will be more efficient than `collect(a')`. If what you actually need is a vector, and not a matrix, use `vec(a)`.

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [April 15, 2021, 11:39am UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/7 "2021-04-15T11:39:42Z")

</div>

> [@Nash](#):
>
> Why is A’ not a 10x1 Array{Int64,2}

If the type of `A'` depended on the number of columns in `A`, that would make things harder for the compiler (since the size of an `Array` can change at runtime).

> [@Nash](#):
>
> how do I convert A to a 10x1 Array{Int64,2}?

In Julia, the answer to the question “how do I convert `x` to a `T`” is usually `T(x)`. In your case:

```julia
Array{Int64,2}(A')

```

(In some rare cases, you have to be more explicit and do `convert(T, x)`.)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 15, 2021, 1:12pm UTC](https://discourse.julialang.org/t/converting-1x10-array-int64-2-to-10x1-array-int64-2/59316/8 "2021-04-15T13:12:40Z")

</div>

> [@Per](#):
>
> `Array{Int64,2}(A')`

`Array(A')` also works.
