/
meanvar.py
81 lines (55 loc) · 2.27 KB
/
meanvar.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# TODO(okuta): Implement median
# TODO(okuta): Implement average
def mean(a, axis=None, dtype=None, out=None, keepdims=False):
"""Returns the arithmetic mean along an axis.
Args:
a (cupy.ndarray): Array to compute mean.
axis (int): Along which axis to compute mean. The flattened array is
used by default.
dtype: Data type specifier.
out (cupy.ndarray): Output array.
keepdims (bool): If ``True``, the axis is remained as an axis of
size one.
Returns:
cupy.ndarray: The mean of the input array along the axis.
.. seealso:: :func:`numpy.mean`
"""
# TODO(okuta): check type
return a.mean(axis=axis, dtype=dtype, out=out, keepdims=keepdims)
def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
"""Returns the variance along an axis.
Args:
a (cupy.ndarray): Array to compute variance.
axis (int): Along which axis to compute variance. The flattened array
is used by default.
dtype: Data type specifier.
out (cupy.ndarray): Output array.
keepdims (bool): If ``True``, the axis is remained as an axis of
size one.
Returns:
cupy.ndarray: The variance of the input array along the axis.
.. seealso:: :func:`numpy.var`
"""
# TODO(okuta): check type
return a.var(axis=axis, dtype=dtype, out=out, ddof=ddof,
keepdims=keepdims)
def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
"""Returns the standard deviation along an axis.
Args:
a (cupy.ndarray): Array to compute standard deviation.
axis (int): Along which axis to compute standard deviation. The
flattened array is used by default.
dtype: Data type specifier.
out (cupy.ndarray): Output array.
keepdims (bool): If ``True``, the axis is remained as an axis of
size one.
Returns:
cupy.ndarray: The standard deviation of the input array along the axis.
.. seealso:: :func:`numpy.std`
"""
# TODO(okuta): check type
return a.std(axis=axis, dtype=dtype, out=out, ddof=ddof,
keepdims=keepdims)
# TODO(okuta): Implement nanmean
# TODO(okuta): Implement nanstd
# TODO(okuta): Implement nanvar