# Literal representation of Array{T,2} when the array is nx1

**URL:** https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821
**Category:** New to Julia
**Tags:** faq
**Created:** [February 4, 2018, 11:03pm UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821 "2018-02-04T23:03:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [February 4, 2018, 11:03pm UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821/1 "2018-02-04T23:03:59Z")

</div>

tl;dr

How do a write a nx1 array literally such that it is an Array{T,2} ?

This all started when I tried to do the following,

```julia
julia> Array{UInt32,2}([1,2])
ERROR: MethodError: Cannot `convert` an object of type Array{Int64,1} to an object of type Array{UInt32,2}
This may have arisen from a call to the constructor Array{UInt32,2}(...),
since type constructors fall back to convert methods.

```

Solution should be easy, I just needed to write an Array{UInt64,2} literally. Another in the category of this should be easy to find, and yet…

```julia
julia> a=reshape([2,1],(2,1))
2×1 Array{Int64,2}:
2
1

julia> println(a)
[2; 1]

julia> [2;1]
2-element Array{Int64,1}:
2
1

julia> 

```

I was expecting [2;1] to be Array{Int64,2}.

It seems like the written representation and the println representation should be consistent.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 5, 2018, 6:30am UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821/2 "2018-02-05T06:30:09Z")

</div>

See

> [@How to create a 2x1 Array?](https://discourse.julialang.org/t/how-to-create-a-2x1-array/8337):
>
> TL;DR, answer: to get a 2x1 Array/Matrix transpose a 1x2 matrix, for example: [2 4]' A more general solution that also works for complex numbers in Julia V0.7- would be transpose([2 4]) I wanted to test julia\> maximum([1 2; 3 4], 2) 2×1 Array{Int64,2}: 2 4 So I tried julia\> maximum([1 2; 3 4], 2) == [2;4] false I expected the value to be true, but the value is false because julia\> [2;4] 2-element Array{Int64,1}: 2 4 That is, a 2×1 Array{Int64,2} is not the same as a 2-element Arra…

This should probably become a FAQ.

---

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [February 6, 2018, 6:11am UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821/3 "2018-02-06T06:11:06Z")

</div>

thank you.

an FAQ or maybe the search engine could have suggested that post ?

i’m sure the AI overlord in charge of searching will make searches more accurate in the future 😉

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [February 6, 2018, 1:02pm UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821/4 "2018-02-06T13:02:20Z")

</div>

The “proper” way is:

```julia
A=zeros(Int32, 2, 1)
A=Array{Int32, 2}(uninitialized, 2, 1)

```

and then fill it however you want. The only thing that is awkward are literal constructors, which are only useful on the repl anyway.

---

<div class="post-metadata">

### Author: ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)
#### Post date: [February 6, 2018, 2:06pm UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821/5 "2018-02-06T14:06:38Z")

</div>

```julia
julia> i32ᵀ(x) = permutedims(Int32.(x)); # Julia 0.7
julia> # i32ᵀ(x) = permutedims(Int32.(x), (2,1)); # Julia 0.6

julia> i32ᵀ([1 2])
2×1 Array{Int32,2}:
 1
 2

```

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 6, 2018, 2:19pm UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821/6 "2018-02-06T14:19:41Z")

</div>

> [@foobar\_lv2](#):
>
> literal constructors, which are only useful on the repl anyway.

or unit tests (for stuff like `mapslices(f, matrix, 2)`), and some other things.

I am undecided about the relevance of this issue: on the one hand it is nice to have literal syntax for things, on the other hand one clearly can’t have it for _everything_. But my impression is that this is an unfortunate corner case of the remnants of some Matlab-like syntax, and if we resolved that we could easily have it.

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [February 6, 2018, 5:09pm UTC](https://discourse.julialang.org/t/literal-representation-of-array-t-2-when-the-array-is-nx1/8821/7 "2018-02-06T17:09:45Z")

</div>

> [@Tamas\_Papp](#):
>
> or unit tests (for stuff like mapslices(f, matrix, 2)), and some other things.

Fair enough; I stand corrected.
