-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathstatistics.py
More file actions
67 lines (51 loc) · 1.77 KB
/
statistics.py
File metadata and controls
67 lines (51 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
#######################################################
# Copyright (c) 2019, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import arrayfire as af
from . import _util
def simple_statistics(verbose=False):
display_func = _util.display_func(verbose)
print_func = _util.print_func(verbose)
a = af.randu(5, 5)
b = af.randu(5, 5)
w = af.randu(5, 1)
display_func(af.mean(a, dim=0))
display_func(af.mean(a, weights=w, dim=0))
print_func(af.mean(a))
print_func(af.mean(a, weights=w))
display_func(af.var(a, dim=0))
display_func(af.var(a, isbiased=True, dim=0))
display_func(af.var(a, weights=w, dim=0))
print_func(af.var(a))
print_func(af.var(a, isbiased=True))
print_func(af.var(a, weights=w))
mean, var = af.meanvar(a, dim=0)
display_func(mean)
display_func(var)
mean, var = af.meanvar(a, weights=w, bias=af.VARIANCE.SAMPLE, dim=0)
display_func(mean)
display_func(var)
display_func(af.stdev(a, dim=0))
print_func(af.stdev(a))
display_func(af.var(a, dim=0))
display_func(af.var(a, isbiased=True, dim=0))
print_func(af.var(a))
print_func(af.var(a, isbiased=True))
display_func(af.median(a, dim=0))
print_func(af.median(w))
print_func(af.corrcoef(a, b))
data = af.iota(5, 3)
k = 3
dim = 0
order = af.TOPK.DEFAULT # defaults to af.TOPK.MAX
assert dim == 0 # topk currently supports first dim only
values, indices = af.topk(data, k, dim, order)
display_func(values)
display_func(indices)
_util.tests["statistics"] = simple_statistics