# 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:** 6

<div class="post-metadata">

### Author: ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)
#### Post date: [April 10, 2020, 1:55pm UTC](https://discourse.julialang.org/t/problem-extracting-a-row-from-an-array-returns-a-column/37331/6 "2020-04-10T13:55:21Z")

</div>

Yeah, I agree with DNF that `N[1:1, :]` is probably more idiomatic.

One way to understand it is that a 1D `Vector` is not the same as an `Nx1` `Matrix` (i.e. a column), even though they are often interchangeable.

The indexing rules in Julia are agnostic to the dimensionality of the array, i.e. they work the same with 1D, 2D, 3D, etc.

See [this post](https://discourse.julialang.org/t/matrix-multiplication-inconsistent-behaviour/36640/23) with some more examples of indexing and dimensionality. The general rule is that when you index dimension `D`, the dimesionality of the result for that dimension is the same as the dimension of the index, so if you index with a zero-dimensional index (a scalar) that dimension is dropped. If you index with a 1-dimensional index (a vector, range, etc.) the dimension is retained. If you index with a 2D index you actually _add_ a dimension.

I _think_ (though I haven’t verified exhaustively) that you can write the general rule as

```julia
resultsize(idxs...) = tuple(Iterators.flatten(size.(idxs))...)

```

i.e. the size of the result is the concatenation of the sizes of the indices.

So 1D and 2D `Array`s aren’t treated specially when it comes to indexing.

---

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