# What does this result mean?

**URL:** <https://discourse.julialang.org/t/what-does-this-result-mean/82137>\
**Category:** General Usage\
**Tags:** bug\
**Created:** [June 2, 2022, 2:24pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137 "2022-06-02T14:24:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [June 2, 2022, 2:24pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/1 "2022-06-02T14:24:00Z")

</div>

```julia
julia> A = [2, 2, 2]
3-element Vector{Int64}:
 2
 2
 2

julia> all(A, dims = 1)
1-element Vector{Bool}:
 0

```

Why does this code return `0`, not `1`?

---

<div class="post-metadata">

**Author:** ![Fliks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fliks/32/2494_2.png) [@Fliks](https://discourse.julialang.org/u/Fliks)\
**Post date:** [June 2, 2022, 2:28pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/2 "2022-06-02T14:28:50Z")

</div>

In Julia unlike python for example values are not considered truthy. See a discussion about this concept here: [On the arbitrariness of truth(iness)](https://discourse.julialang.org/t/on-the-arbitrariness-of-truth-iness/81381).  
If you would like to test whether all values are nonzero for example you could provide a function to the all function:

```julia
julia> all(!iszero, [2,2,2], dims=1)
1-element Vector{Bool}:
 1

```

---

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [June 2, 2022, 2:30pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/3 "2022-06-02T14:30:54Z")

</div>

Thanks, but why does this code return 1?

```julia
julia> all([3, 3, 3], dims = 1)
1-element Vector{Bool}:
 1

```

---

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [June 2, 2022, 2:41pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/4 "2022-06-02T14:41:11Z")

</div>

```julia
julia> for i in 0:10
           A = i * ones(Int, 3)
          @show all(A, dims = 1)
       end
all(A, dims = 1) = Bool[0]
all(A, dims = 1) = Bool[1]
all(A, dims = 1) = Bool[0]
all(A, dims = 1) = Bool[1]
all(A, dims = 1) = Bool[0]
all(A, dims = 1) = Bool[1]
all(A, dims = 1) = Bool[0]
all(A, dims = 1) = Bool[1]
all(A, dims = 1) = Bool[0]
all(A, dims = 1) = Bool[1]
all(A, dims = 1) = Bool[0]

```

---

<div class="post-metadata">

**Author:** ![s-broda](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/s-broda/32/3946_2.png) [@s-broda](https://discourse.julialang.org/u/s-broda)\
**Post date:** [June 2, 2022, 3:12pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/5 "2022-06-02T15:12:26Z")

</div>

Wow, that’s wild. Looks like a bug to me. This should probably just error, like it does without the `dims` keyword argument:

```julia
all([1, 1, 1])
ERROR: TypeError: non-boolean (Int64) used in boolean context
Stacktrace:
 [1] _all
   @ .\reduce.jl:1161 [inlined]
 [2] _all
   @ .\reducedim.jl:903 [inlined]
 [3] #all#750
   @ .\reducedim.jl:901 [inlined]
 [4] all(a::Vector{Int64})
   @ Base .\reducedim.jl:901
 [5] top-level scope
   @ REPL[21]:1

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 2, 2022, 3:28pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/6 "2022-06-02T15:28:57Z")

</div>

This boils down to

```julia
julia> mapreduce(identity, &, [3,3,3]; dims=1)
1-element Vector{Bool}:
 1

julia> mapreduce(identity, &, [2,2,2]; dims=1)
1-element Vector{Bool}:
 0

```

and definitely is a bug.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 2, 2022, 3:29pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/7 "2022-06-02T15:29:32Z")

</div>

Related:

```julia
julia> any([1, 2], dims=1)
ERROR: InexactError: Bool(3)

```

Like, I guess it’s good that it gives an error, but it’s not really the right error.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 2, 2022, 3:47pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/8 "2022-06-02T15:47:32Z")

</div>

> [@pfitzseb](#):
>
> This boils down to
> 
> `julia> mapreduce(identity, &, [3,3,3]; dims=1)`

Could you provide some tips how to get there? Thanks.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 2, 2022, 3:52pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/9 "2022-06-02T15:52:30Z")

</div>

`@edit all([3, 3, 3], dims = 1)` and scroll down to

```julia
$(_fname)(f, A, dims; kw...) = mapreduce(f, $(op), A; dims=dims, kw...)

```

You could also `@enter all([3, 3, 3], dims = 1)` (in VS Code or with Debugger.jl loaded) and then step around a bit until you end up in that function (which may be annoying because the kwarg wrapper heuristics are kinda borked).

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 2, 2022, 3:59pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/10 "2022-06-02T15:59:31Z")

</div>

Thanks Sebastian. And sorry, my brain is overheating: I cannot see the connection between “all vector elements being true” and that unfamiliar mapreduce expression. (_if all vector elements are booleans, it is a bit more easy to see_)

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 2, 2022, 4:06pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/11 "2022-06-02T16:06:05Z")

</div>

Well,

```julia
any(x) == mapreduce(is_truthy, |, x) == is_truthy(x[1]) | is_truthy(x[2]) | ... | is_truthy(x[end])
all(x) == mapreduce(is_truthy, &, x) == is_truthy(x[1]) & is_truthy(x[2]) & ... & is_truthy(x[end])

```

For booleans, `is_truthy == identity`. This of course breaks down when the `eltype` of `x` is e.g. an integer like in the example above, because in that case `|`/`&` means bitwise-or/and.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 2, 2022, 4:07pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/12 "2022-06-02T16:07:37Z")

</div>

Thanks a lot for your explanation, it is very clear now.

---

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [June 2, 2022, 7:38pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/13 "2022-06-02T19:38:08Z")

</div>

> [@pfitzseb](#):
>
> `mapreduce(identity, &, [3,3,3]; dims=1)`

```julia
julia> mapreduce(is_truthy, &, [3, 3, 3])
ERROR: UndefVarError: is_truthy not defined
Stacktrace:
 [1] top-level scope
   @ REPL[91]:1

```

I get an error. is\_truthy not defined.

---

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [June 2, 2022, 7:44pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/14 "2022-06-02T19:44:39Z")

</div>

This is a julia bug. @Raymond, do you want to have the honor of filing an [issue](https://github.com/JuliaLang/julia/issues/new/choose) since you found it? 🙂

---

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [June 2, 2022, 7:49pm UTC](https://discourse.julialang.org/t/what-does-this-result-mean/82137/15 "2022-06-02T19:49:17Z")

</div>

Oh, Yes.  
So it is a bug. I will file an issue in github.
