# Vector comprehension example

**URL:** <https://discourse.julialang.org/t/vector-comprehension-example/26344>\
**Category:** General Usage\
**Created:** [July 14, 2019, 2:17pm UTC](https://discourse.julialang.org/t/vector-comprehension-example/26344 "2019-07-14T14:17:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [July 14, 2019, 2:17pm UTC](https://discourse.julialang.org/t/vector-comprehension-example/26344/1 "2019-07-14T14:17:36Z")

</div>

The following is the code.

```julia
v=[2,3,4]
v[[true for i in v]]

```

It would return a 3-element Array{Int64,1}, [2,3,4]. It looks a bit strange to me. Originally, I thought it would return a matrix. I was wondering, how do you understand it?

---

<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:** [July 14, 2019, 2:26pm UTC](https://discourse.julialang.org/t/vector-comprehension-example/26344/2 "2019-07-14T14:26:35Z")

</div>

Aren’t you just indexing with a boolean mask? I.e. you are doing

```julia
v[[true, true, true]] 

```

So selecting all elements in v

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [July 14, 2019, 2:38pm UTC](https://discourse.julialang.org/t/vector-comprehension-example/26344/3 "2019-07-14T14:38:31Z")

</div>

A boolean-array index always yields a vector, and I don’t see how it could be different.  
Otherwise, what shape should this be:

```julia
v = [1 2; 3 4]
v[v.>1]

```
