# Preserving matrix structure while using Boolean arrays

**URL:** https://discourse.julialang.org/t/preserving-matrix-structure-while-using-boolean-arrays/21220
**Category:** General Usage
**Created:** [February 26, 2019, 4:38pm UTC](https://discourse.julialang.org/t/preserving-matrix-structure-while-using-boolean-arrays/21220 "2019-02-26T16:38:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://discourse.julialang.org/u/jfan)
#### Post date: [February 26, 2019, 4:38pm UTC](https://discourse.julialang.org/t/preserving-matrix-structure-while-using-boolean-arrays/21220/1 "2019-02-26T16:38:32Z")

</div>

Let’s say,

> x  
> 5x3 Array{Int64,2}:  
> 1 6 11  
> 2 7 12  
> 3 8 13  
> 4 9 14  
> 5 10 15  
> c  
> 5x3 BitArray{2}:  
> true true false  
> false false false  
> false false false  
> false true false  
> true false true

Up to versions 0.6 I used to get:

> x[!c] .= 0  
> 5x3 Array{Int64,2}:  
> 1 6 0  
> 0 0 0  
> 0 0 0  
> 0 9 0  
> 5 0 15

But, in \> 0.7 versions,

> x[.!c] .= 0  
> 10-element view(::Array{Int64,1}, [2, 3, 4, 7, 8, 10, 11, 12, 13, 14]) with eltype Int64:  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0

Is there a way to preserve the structure of the matrix like in versions 0.6?  
Thanks!

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [February 26, 2019, 4:39pm UTC](https://discourse.julialang.org/t/preserving-matrix-structure-while-using-boolean-arrays/21220/2 "2019-02-26T16:39:25Z")

</div>

Note that this still preserves the structure of `x`: this happens to be different than the return value of `setindex!`:

```julia
julia> x = [1 2; 3 4]
2×2 Array{Int64,2}:
 1 2
 3 4

julia> c = [true false; true false]
2×2 Array{Bool,2}:
 true false
 true false

julia> x[.!c] .= 0
2-element view(::Array{Int64,1}, [3, 4]) with eltype Int64:
 0
 0

julia> x
2×2 Array{Int64,2}:
 1 0
 3 0

```

You can also do `x .*= c`.

---

<div class="post-metadata">

### Author: ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://discourse.julialang.org/u/jfan)
#### Post date: [February 26, 2019, 4:52pm UTC](https://discourse.julialang.org/t/preserving-matrix-structure-while-using-boolean-arrays/21220/3 "2019-02-26T16:52:44Z")

</div>

> [@jfan](#):
>
> 10-element view(::Array{Int64,1}, [2, 3, 4, 7, 8, 10, 11, 12, 13, 14]) with eltype Int64:  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0  
> 0

Well thanks much for clarifying. I should have checked that before posting - sorry! However, the x .\*=c is good to know.
