'Create Array of same Size
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.
Solution 1:[1]
One solution would be:
size(a) |> falses
2×3 BitMatrix:
0 0 0
0 0 0
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Georgery |
| Solution 2 | Andrej Oskin |
