Create Array of same Size

Viewed 74

I have an array

a = zeros(2,3)

2×3 Matrix{Float64}:
 0.0  0.0  0.0
 0.0  0.0  0.0

and I want to create a Bool array of same size with all values set to false.

3 Answers

Another option is to use zeros with Bool as the type option:

julia> zeros(Bool, size(a))
2×3 Matrix{Bool}:
 0  0  0
 0  0  0

One solution would be:

size(a) |> falses

2×3 BitMatrix:
 0  0  0
 0  0  0

You can combine similar and fill! to achieve what you want.

julia> a = zeros(2,3)
2×3 Matrix{Float64}:
 0.0  0.0  0.0
 0.0  0.0  0.0

julia> fill!(similar(a, Bool), false)
2×3 Matrix{Bool}:
 0  0  0
 0  0  0
Related