Hi @Saransh-cpp
dims is used to specify on which dimensions you want to calculate the std on…
Let’s say for example we have two 3-channel images of size (4, 4) as below →
julia> using Statistics
# two 3-channel images of size (4, 4)
julia> xs = rand(3, 4, 4, 2)
3×4×4×2 Array{Float64, 4}:
[:, :, 1, 1] =
0.638898 0.0607577 0.248664 0.134614
0.359026 0.045089 0.934976 0.208916
0.574276 0.00640597 0.916209 0.146101
[:, :, 2, 1] =
0.337945 0.385004 0.941823 0.879369
0.00222145 0.191058 0.53481 0.513988
0.760298 0.589457 0.286568 0.510345
[:, :, 3, 1] =
0.815596 0.157969 0.623036 0.0807889
0.557733 0.813058 0.474988 0.159235
0.893057 0.386838 0.570377 0.518802
[:, :, 4, 1] =
0.104052 0.380098 0.268024 0.578795
0.413343 0.998084 0.449842 0.224211
0.864892 0.808143 0.0459052 0.457739
[:, :, 1, 2] =
0.24586 0.870185 0.770928 0.31385
0.3981 0.391596 0.845867 0.146243
0.114382 0.0579019 0.247182 0.0315621
[:, :, 2, 2] =
0.306497 0.418139 0.713051 0.87407
0.14916 0.302198 0.621749 0.0677304
0.753772 0.00230659 0.938192 0.106774
[:, :, 3, 2] =
0.624643 0.598719 0.160968 0.766046
0.755545 0.0378673 0.397636 0.86422
0.809038 0.915949 0.0150156 0.0320573
[:, :, 4, 2] =
0.128597 0.0363205 0.862884 0.957192
0.646652 0.159509 0.553012 0.71586
0.5693 0.270781 0.950244 0.844724
# std on over all numbers (on all dims)
julia> std(xs, dims=[1, 2, 3, 4])
1×1×1×1 Array{Float64, 4}:
[:, :, 1, 1] =
0.308191790621495
# we will just get a single number, preserving input shape (x, x, x, x)
# std on batch dimension (i.e, last dim), we specify 1st 3 dims to calc std on
julia> std(xs, dims=[1, 2, 3])
1×1×1×2 Array{Float64, 4}:
[:, :, 1, 1] =
0.29192537121237955
[:, :, 1, 2] =
0.32666112721755525
# we will just get two numbers, each for one image
# std on channel dimension (i.e, first dim), we specify last 3 dims to calc std on
julia> std(xs, dims=[2, 3, 4])
3×1×1×1 Array{Float64, 4}:
[:, :, 1, 1] =
0.30341597287159655
0.2841992921298127
0.34238183603676203
# we will just get three numbers, each for one channel
Input shape will be preserved in outputs, IMO there is no real benefit of thinking in terms of output dim, rather we can just think of it as numbers with length == dim length you wanted the output to be on.