Skip to content

Commit e537708

Browse files
authored
Merge pull request #165 from jvdp1/spec_md
Example in specs for stats
2 parents de38699 + e126d59 commit e537708

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/stdlib_experimental_stats.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ program demo_mean
4040
use stdlib_experimental_stats, only: mean
4141
implicit none
4242
real :: x(1:6) = [ 1., 2., 3., 4., 5., 6. ]
43-
print *, mean(x) !returns 3.5
44-
print *, mean( reshape(x, [ 2, 3 ] )) !returns 3.5
45-
print *, mean( reshape(x, [ 2, 3 ] ), 1) !returns [ 1.5, 3.5, 5.5 ]
46-
print *, mean( reshape(x, [ 2, 3 ] ), 1,&
47-
reshape(x, [ 2, 3 ] ) > 3.) !returns [ NaN, 4.0, 5.5 ]
43+
real :: y(1:2, 1:3) = reshape([ 1., 2., 3., 4., 5., 6. ], [ 2, 3])
44+
print *, mean(x) !returns 3.5
45+
print *, mean(y) !returns 3.5
46+
print *, mean(y, 1) !returns [ 1.5, 3.5, 5.5 ]
47+
print *, mean(y, 1,y > 3.) !returns [ NaN, 4.0, 5.5 ]
4848
end program demo_mean
4949
```
5050

@@ -102,16 +102,16 @@ If `mask` is specified, the result is the _k_-th (central) moment of all elemen
102102

103103
```fortran
104104
program demo_moment
105-
use stdlib_experimental_stats, only: mean, moment
105+
use stdlib_experimental_stats, only: moment
106106
implicit none
107107
real :: x(1:6) = [ 1., 2., 3., 4., 5., 6. ]
108108
real :: y(1:2, 1:3) = reshape([ 1., 2., 3., 4., 5., 6. ], [ 2, 3])
109-
print *, moment(x, 2) !returns 2.9167
110-
print *, moment( y, 2) !returns 2.9167
111-
print *, moment( y, 2, 1) !returns [0.25, 0.25, 0.25]
112-
print *, moment( y, 2, 1, mask = (y > 3.)) !returns [NaN, 0., 0.25]
113-
print *, moment(x, 2, center = 0.) !returns 15.1667
114-
print *, moment( y, 1, 1, center = 0.) !returns [1.5, 3.5, 5.5]
109+
print *, moment(x, 2) !returns 2.9167
110+
print *, moment(y, 2) !returns 2.9167
111+
print *, moment(y, 2, 1) !returns [0.25, 0.25, 0.25]
112+
print *, moment(y, 2, 1, mask = (y > 3.)) !returns [NaN, 0., 0.25]
113+
print *, moment(x, 2, center = 0.) !returns 15.1667
114+
print *, moment(y, 1, 1, center = 0.) !returns [1.5, 3.5, 5.5]
115115
end program demo_moment
116116
```
117117

@@ -166,15 +166,13 @@ program demo_var
166166
use stdlib_experimental_stats, only: var
167167
implicit none
168168
real :: x(1:6) = [ 1., 2., 3., 4., 5., 6. ]
169-
print *, var(x) !returns 3.5
170-
print *, var(x, corrected = .false.) !returns 2.9167
171-
print *, var( reshape(x, [ 2, 3 ] )) !returns 3.5
172-
print *, var( reshape(x, [ 2, 3 ] ), 1) !returns [0.5, 0.5, 0.5]
173-
print *, var( reshape(x, [ 2, 3 ] ), 1,&
174-
reshape(x, [ 2, 3 ] ) > 3.) !returns [NaN, NaN, 0.5]
175-
print *, var( reshape(x, [ 2, 3 ] ), 1,&
176-
reshape(x, [ 2, 3 ] ) > 3.,&
177-
corrected=.false.) !returns [NaN, 0., 0.25]
169+
real :: y(1:2, 1:3) = reshape([ 1., 2., 3., 4., 5., 6. ], [ 2, 3])
170+
print *, var(x) !returns 3.5
171+
print *, var(x, corrected = .false.) !returns 2.9167
172+
print *, var(y) !returns 3.5
173+
print *, var(y, 1) !returns [0.5, 0.5, 0.5]
174+
print *, var(y, 1, y > 3.) !returns [NaN, NaN, 0.5]
175+
print *, var(y, 1, y > 3., corrected=.false.) !returns [NaN, 0., 0.25]
178176
end program demo_var
179177
```
180178

0 commit comments

Comments
 (0)