# Boolean Indexing

**URL:** <https://discourse.julialang.org/t/boolean-indexing/82556>\
**Category:** General Usage\
**Tags:** indexing, boolean\
**Created:** [June 10, 2022, 9:17am UTC](https://discourse.julialang.org/t/boolean-indexing/82556 "2022-06-10T09:17:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lazycoder](https://avatars.discourse-cdn.com/v4/letter/l/4da419/32.png) [@lazycoder](https://discourse.julialang.org/u/lazycoder)\
**Post date:** [June 10, 2022, 9:17am UTC](https://discourse.julialang.org/t/boolean-indexing/82556/1 "2022-06-10T09:17:44Z")

</div>

I’m a little confused on boolean indexing, I’m trying to do something like this:

```julia
test=5.4
res=fill(0,size(test))
res[test .> 5] .=5

```

The size of test could be one or more, but when test is a size of one I get an error where I can’t access the element.

Any suggestions?

Thanks!

---

<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:** [June 10, 2022, 9:31am UTC](https://discourse.julialang.org/t/boolean-indexing/82556/2 "2022-06-10T09:31:43Z")

</div>

You can’t index a vector with a single `Bool`, it needs to be a vector of bools, see the docs here:

[https://docs.julialang.org/en/v1/manual/arrays/#Logical-indexing](https://docs.julialang.org/en/v1/manual/arrays/#Logical-indexing)

Are you maybe looking for

```julia
res = ifelse.(test .> 5, 5, 0)

```

?

---

<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:** [June 10, 2022, 1:30pm UTC](https://discourse.julialang.org/t/boolean-indexing/82556/3 "2022-06-10T13:30:24Z")

</div>

You should also be aware that the size of `test` is not 1, but

```julia
julia> size(test)
()

```

since `res` is a scalar and not an array. So therefore, `res` becomes a zero-dimensional array:

```julia
julia> res = fill(0, size(test))
0-dimensional Array{Int64, 0}:
0

```
