Preserving matrix structure while using Boolean arrays

#1

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!

#2

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

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.

1 Like
#3

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