Tue 25 Jul 2017 07:59:13 AM UTC, comment #9:
I understand that NaN or empty array is returned depending on dimension.
Strange was directed to the case that
mean(zeros(1,0)) leads to dim 2 and
mean(zeros(2,0)) leads to dim 1.
This is not generic beahvior in my opinion.

Mon 24 Jul 2017 11:28:06 PM UTC, comment #8:
Other languages which are far stronger in statistics, such as R, return NaN for the case of empty matrices. Sample R code,
It seems more useful mathematically for Octave to return NaN in these cases rather than occasionally NaN and occasionally a dimensioned empty matrix, even if there is a rule for when "occasionally" occurs.

Mon 24 Jul 2017 10:34:21 PM UTC, comment #7:
It's not strange behaviour. 'mean' with 1 input applies along the first nonsingleton dimension. 'mean (zeros (1,0))' averages along the second dim and so gives NaN. 'mean (zeros (2,0))' averages along the first and so gives zeros(1,0). Try using dimension as a second input to 'mean'

Mon 17 Jul 2017 08:09:34 AM UTC, comment #6:
It's a strange behavior:
mean (zeros (0,0)) = NaN
mean (zeros (1,0)) = NaN
mean (zeros (2,0)) = 1x0
Documentation of mean() only says about NaN:
If A is an empty 0by0 matrix, then mean(A) returns NaN
The same for std().

Fri 14 Jul 2017 09:02:22 PM UTC, comment #5:
Why, as a mathematical proposition, shouldn't mean() return NaN for all empty matrices?
I can't find any easy pattern to the results that you have from Matlab. It seems to me that this may be an instance where Octave does not want to follow Matlab exactly since there seems to be quirks of implementation here, rather than reasonable mathematical results.
If you could, try these further tests in Matlab:

Thu 13 Jul 2017 05:38:50 AM UTC, comment #4:
Results are from Matlab 2016b.

Thu 13 Jul 2017 05:36:38 AM UTC, comment #3:
Here's a complete list up to dimesion three for mean(zeros(i,j,k), dim) and last for mean(zeros(i,j,k)) without dim:
i j k dim ret
 0 0 1 1×0×0
 0 1 1×0
 1 0 1×1×0
 1 1 NaN
1 0 0 1×0×0
1 0 1 1×0
1 1 0 1×1×0
1 1 1 0
i j k dim ret
 0 0 2 0×1×0
 0 1 0x1
 1 0 0×1×0
 1 1 0x1
1 0 0 1x1x0
1 0 1 NaN
1 1 0 1x1x0
1 1 1 0
i j k dim ret
 0 0 3 []
 0 1 []
 1 0 0x1
 1 1 0x1
1 0 0 1x0
1 0 1 1x0
1 1 0 NaN
1 1 1 0
i j k dim ret
 0 0 1x0x0
 0 1 NaN
 1 0 1x1x0
 1 1 NaN
1 0 0 1x1x0
1 0 1 NaN
1 1 0 NaN
1 1 1 0
Hope this is useful.

Wed 12 Jul 2017 06:20:06 PM UTC, comment #2:
Confirmed. I'm pretty sure Matlab changed this relatively recently and that it used to return []. It doesn't look that hard to fix, just a special test for empty inputs. You can see that Matlab has changed because the Octave function supports a flag that allows you to specify arithmetic mean, geometric mean, or harmonic mean. That used to be part of Matlab.

Tue 11 Jul 2017 10:11:11 AM UTC, comment #1:
The same for the std() method.

Tue 11 Jul 2017 07:43:34 AM UTC, original submission:
In Matlab mean of an empty input returns NaN, however,
Octave returns [](1x0) for "mean(zeros(1,0))".
Obviously it is the case if empty input size at dimension dim is not zero, e.g. also "mean(zeros(0,1), 2)" returns [](0x1).
