如果布尔向量全部为假,如何检查julia

如果布尔向量全部为假,如何检查julia,julia,Julia,我只是想知道是否有一些预先内置的和() filter = [true,false,true,false] length([i for i in filter if i]) > 0 # true filter = [false,false,false] length([i for i in filter if i]) > 0 # false 对不起,你说的全是谎言。然后: julia> all(!, x) 或 对不起,你说的全是谎言。然后: julia> all(!,

我只是想知道是否有一些预先内置的
和()

filter = [true,false,true,false]
length([i for i in filter if i]) > 0 # true

filter = [false,false,false]
length([i for i in filter if i]) > 0 # false
对不起,你说的全是谎言。然后:

julia> all(!, x)

对不起,你说的全是谎言。然后:

julia> all(!, x)


这不是对您问题的回答,但请注意,
filter
是一个现有函数,因此您可能不想覆盖它

julia> a = [true, false, true, false];
julia> filter(!, a)
 2-element Array{Bool,1}:
 false
 false
julia> filter(!!, a)
 2-element Array{Bool,1}:
 true
 true

这不是对您问题的回答,但请注意,
filter
是一个现有函数,因此您可能不想覆盖它

julia> a = [true, false, true, false];
julia> filter(!, a)
 2-element Array{Bool,1}:
 false
 false
julia> filter(!!, a)
 2-element Array{Bool,1}:
 true
 true
sum()
实际上是最快的:

x = falses(1_000_000)

julia> @benchmark sum(x)
BenchmarkTools.Trial:
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     2.834 μs (0.00% GC)
  median time:      2.905 μs (0.00% GC)
  mean time:        3.079 μs (0.00% GC)
  maximum time:     12.648 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     9

julia> @benchmark all(!, x)
BenchmarkTools.Trial:
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     546.055 μs (0.00% GC)
  median time:      546.463 μs (0.00% GC)
  mean time:        558.960 μs (0.00% GC)
  maximum time:     1.709 ms (0.00% GC)
  --------------
  samples:          8928
  evals/sample:     1

@benchmark any(x)
BenchmarkTools.Trial:
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     5.728 μs (0.00% GC)
  median time:      5.752 μs (0.00% GC)
  mean time:        6.044 μs (0.00% GC)
  maximum time:     28.300 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     6
sum()
实际上是最快的:

x = falses(1_000_000)

julia> @benchmark sum(x)
BenchmarkTools.Trial:
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     2.834 μs (0.00% GC)
  median time:      2.905 μs (0.00% GC)
  mean time:        3.079 μs (0.00% GC)
  maximum time:     12.648 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     9

julia> @benchmark all(!, x)
BenchmarkTools.Trial:
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     546.055 μs (0.00% GC)
  median time:      546.463 μs (0.00% GC)
  mean time:        558.960 μs (0.00% GC)
  maximum time:     1.709 ms (0.00% GC)
  --------------
  samples:          8928
  evals/sample:     1

@benchmark any(x)
BenchmarkTools.Trial:
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     5.728 μs (0.00% GC)
  median time:      5.752 μs (0.00% GC)
  mean time:        6.044 μs (0.00% GC)
  maximum time:     28.300 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     6

有函数
any
有函数
any