# Boolean indexing deprecated?

**URL:** https://discourse.julialang.org/t/boolean-indexing-deprecated/7299
**Category:** General Usage
**Tags:** question, deprecation
**Created:** [November 25, 2017, 2:22am UTC](https://discourse.julialang.org/t/boolean-indexing-deprecated/7299 "2017-11-25T02:22:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 25, 2017, 2:22am UTC](https://discourse.julialang.org/t/boolean-indexing-deprecated/7299/1 "2017-11-25T02:22:19Z")

</div>

From the [NEWS.md](https://github.com/JuliaLang/julia/blob/master/NEWS.md) file:

> Using Bool values directly as indices is now deprecated and will be an error in the future. Convert them to Int before indexing if you intend to access index 1 for true and 0 for false.

Does that mean that we won’t be able to mask arrays with boolean masks anymore? That sounds terrible, can someone please clarify this?

---

<div class="post-metadata">

### Author: ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)
#### Post date: [November 25, 2017, 2:25am UTC](https://discourse.julialang.org/t/boolean-indexing-deprecated/7299/2 "2017-11-25T02:25:23Z")

</div>

```julia
julia> a = [1,2]
2-element Array{Int64,1}:
 1
 2

julia> a[[false, true]]
1-element Array{Int64,1}:
 2

julia> a[true]
WARNING: indexing with Bool values is deprecated. Convert the index to an integer first with `Int(i)`.
Stacktrace:
 [1] depwarn(::String, ::Tuple{Symbol,Symbol,Symbol}) at ./deprecated.jl:68
 [2] to_index at ./deprecated.jl:1854 [inlined]
 [3] to_index at ./indices.jl:173 [inlined]
 [4] to_indices at ./indices.jl:218 [inlined]
 [5] to_indices at ./multidimensional.jl:512 [inlined]
 [6] getindex(::Array{Int64,1}, ::Bool) at ./multidimensional.jl:372
 [7] top-level scope
 [8] eval(::Module, ::Expr) at ./repl/REPL.jl:3
 [9] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./repl/REPL.jl:69
 [10] macro expansion at ./repl/REPL.jl:100 [inlined]
 [11] (::getfield(Base.REPL, Symbol("##1#2")){Base.REPL.REPLBackend})() at ./event.jl:95
in expression starting at no file:0
1

julia> a[false]
ERROR: BoundsError: attempt to access 2-element Array{Int64,1} at index [0]
Stacktrace:
 [1] getindex(::Array{Int64,1}, ::Bool) at ./multidimensional.jl:372
 [2] top-level scope

```

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 25, 2017, 2:27am UTC](https://discourse.julialang.org/t/boolean-indexing-deprecated/7299/3 "2017-11-25T02:27:31Z")

</div>

Thank you @Keno for clarifying the note in the NEWS, I was about to have a mental crisis 🙂

---

<div class="post-metadata">

### Author: ![system](https://global.discourse-cdn.com/julialang/original/3X/1/2/12829a7ba92b924d4ce81099cbf99785bee9b405.png) [@system](https://discourse.julialang.org/u/system)
#### Post date: [November 26, 2017, 2:27am UTC](https://discourse.julialang.org/t/boolean-indexing-deprecated/7299/4 "2017-11-26T02:27:49Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
