# Understanding the behavior of the geometric mean for multidimensional arrays

**URL:** <https://discourse.julialang.org/t/understanding-the-behavior-of-the-geometric-mean-for-multidimensional-arrays/64507>\
**Category:** New to Julia\
**Created:** [July 12, 2021, 1:41pm UTC](https://discourse.julialang.org/t/understanding-the-behavior-of-the-geometric-mean-for-multidimensional-arrays/64507 "2021-07-12T13:41:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://discourse.julialang.org/u/josimar)\
**Post date:** [July 12, 2021, 1:41pm UTC](https://discourse.julialang.org/t/understanding-the-behavior-of-the-geometric-mean-for-multidimensional-arrays/64507/1 "2021-07-12T13:41:23Z")

</div>

I would like to understand how I can take the geometric mean of an array across a certain dimension. For the mean value, I normally use:

> mean(x, dims=1)

But the same does not work for geometric mean, why?

```julia
using Statistics

x = [1 2 3 ; 4 5 6]
geomean(x, dims=1)

ERROR: MethodError: no method matching geomean(::Array{Int64,2}; dims=1)
Closest candidates are:
  geomean(::Any) at /home/josimar/.julia/packages/StatsBase/548SN/src/scalarstats.jl:16 got unsupported keyword argument "dims"
Stacktrace:
 [1] top-level scope at REPL[30]:1

```

Note that the above error for the `geomean` also occurs for the `harmmean` and `percentile`.

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [July 12, 2021, 2:15pm UTC](https://discourse.julialang.org/t/understanding-the-behavior-of-the-geometric-mean-for-multidimensional-arrays/64507/2 "2021-07-12T14:15:27Z")

</div>

These functions (which are part of StatsBase.jl, not Julia itself) do not support the `dims` keyword. There is [an issue](https://github.com/JuliaStats/StatsBase.jl/issues/77) for adding this functionality.

You can use `geomean.(eachcol(x))` instead, but it will return a vector instead of a row matrix:

```julia
julia> using StatsBase

julia> x = [1 2 3 ; 4 5 6]
2×3 Matrix{Int64}:
 1 2 3
 4 5 6

julia> geomean.(eachcol(x))
3-element Vector{Float64}:
 2.0
 3.162277660168379
 4.242640687119285

```
