# Problem: extracting a row from an array, returns a column

**URL:** <https://discourse.julialang.org/t/problem-extracting-a-row-from-an-array-returns-a-column/37331>\
**Category:** General Usage\
**Tags:** question, arrays\
**Created:** [April 10, 2020, 11:33am UTC](https://discourse.julialang.org/t/problem-extracting-a-row-from-an-array-returns-a-column/37331 "2020-04-10T11:33:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [April 10, 2020, 12:11pm UTC](https://discourse.julialang.org/t/problem-extracting-a-row-from-an-array-returns-a-column/37331/2 "2020-04-10T12:11:30Z")

</div>

The quick way of obtaining what you want is:

```julia
julia> N[[1],:]
1×2 Array{Int64,2}:
 1 2

```

I,e. instead of giving a scalar index, pass a collection of indices for slicing, like when you do `N[1:2,:]` - although that collection has only one index.

Longer explanation of why is it like that in a recent discussion:

> [@Trouble Understanding Slicing](https://discourse.julialang.org/t/trouble-understanding-slicing/36821/):
>
> In the following code, I can’t understand why sum(a[1,:],dims=2) gives a different answer then the first row of sum(a[1:2,:],dims=2). julia\> a = [1 2 3 4; 5 6 7 8; 9 10 11 12]; julia\> sum(a, dims=2) 3×1 Array{Int64,2}: 10 26 42 julia\> sum(a[1:2,:], dims=2) 2×1 Array{Int64,2}: 10 26 julia\> sum(a[1,:], dims=2) 4-element Array{Int64,1}: 1 2 3 4 julia\>

---

_[View the full topic](https://discourse.julialang.org/t/problem-extracting-a-row-from-an-array-returns-a-column/37331)._
