Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6137a6f

Browse files
mlloreda9prady9
authored andcommitted
Documented statistics API.
1 parent 548b321 commit 6137a6f

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

‎arrayfire/statistics.py‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@
1515
from .array import *
1616

1717
def mean(a, weights=None, dim=None):
18+
"""
19+
Calculate mean along a given dimension.
20+
21+
Parameters
22+
----------
23+
a: af.Array
24+
The input array.
25+
26+
weights: optional: af.Array. default: None.
27+
Array to calculate the weighted mean. Must match size of the
28+
input array.
29+
30+
dim: optional: int. default: None.
31+
The dimension for which to obtain the mean from input data.
32+
33+
Returns
34+
-------
35+
output: af.Array
36+
Array containing the mean of the input array along a given
37+
dimension.
38+
"""
1839
if dim is not None:
1940
out = Array()
2041

@@ -39,6 +60,31 @@ def mean(a, weights=None, dim=None):
3960
return real if imag == 0 else real + imag * 1j
4061

4162
def var(a, isbiased=False, weights=None, dim=None):
63+
"""
64+
Calculate variance along a given dimension.
65+
66+
Parameters
67+
----------
68+
a: af.Array
69+
The input array.
70+
71+
isbiased: optional: Boolean. default: False.
72+
Boolean denoting population variance (false) or sample
73+
variance (true).
74+
75+
weights: optional: af.Array. default: None.
76+
Array to calculate for the weighted mean. Must match size of
77+
the input array.
78+
79+
dim: optional: int. default: None.
80+
The dimension for which to obtain the variance from input data.
81+
82+
Returns
83+
-------
84+
output: af.Array
85+
Array containing the variance of the input array along a given
86+
dimension.
87+
"""
4288
if dim is not None:
4389
out = Array()
4490

@@ -63,6 +109,24 @@ def var(a, isbiased=False, weights=None, dim=None):
63109
return real if imag == 0 else real + imag * 1j
64110

65111
def stdev(a, dim=None):
112+
"""
113+
Calculate standard deviation along a given dimension.
114+
115+
Parameters
116+
----------
117+
a: af.Array
118+
The input array.
119+
120+
dim: optional: int. default: None.
121+
The dimension for which to obtain the standard deviation from
122+
input data.
123+
124+
Returns
125+
-------
126+
output: af.Array
127+
Array containing the standard deviation of the input array
128+
along a given dimension.
129+
"""
66130
if dim is not None:
67131
out = Array()
68132
safe_call(backend.get().af_stdev(c_pointer(out.arr), a.arr, c_int_t(dim)))
@@ -76,6 +140,26 @@ def stdev(a, dim=None):
76140
return real if imag == 0 else real + imag * 1j
77141

78142
def cov(a, isbiased=False, dim=None):
143+
"""
144+
Calculate covariance along a given dimension.
145+
146+
Parameters
147+
----------
148+
a: af.Array
149+
The input array.
150+
151+
isbiased: optional: Boolean. default: False.
152+
Boolean denoting whether biased estimate should be taken.
153+
154+
dim: optional: int. default: None.
155+
The dimension for which to obtain the covariance from input data.
156+
157+
Returns
158+
-------
159+
output: af.Array
160+
Array containing the covariance of the input array along a
161+
given dimension.
162+
"""
79163
if dim is not None:
80164
out = Array()
81165
safe_call(backend.get().af_cov(c_pointer(out.arr), a.arr, isbiased, c_int_t(dim)))
@@ -89,6 +173,23 @@ def cov(a, isbiased=False, dim=None):
89173
return real if imag == 0 else real + imag * 1j
90174

91175
def median(a, dim=None):
176+
"""
177+
Calculate median along a given dimension.
178+
179+
Parameters
180+
----------
181+
a: af.Array
182+
The input array.
183+
184+
dim: optional: int. default: None.
185+
The dimension for which to obtain the median from input data.
186+
187+
Returns
188+
-------
189+
output: af.Array
190+
Array containing the median of the input array along a
191+
given dimension.
192+
"""
92193
if dim is not None:
93194
out = Array()
94195
safe_call(backend.get().af_median(c_pointer(out.arr), a.arr, c_int_t(dim)))
@@ -102,6 +203,22 @@ def median(a, dim=None):
102203
return real if imag == 0 else real + imag * 1j
103204

104205
def corrcoef(x, y):
206+
"""
207+
Calculate the correlation coefficient of the input arrays.
208+
209+
Parameters
210+
----------
211+
x: af.Array
212+
The first input array.
213+
214+
y: af.Array
215+
The second input array.
216+
217+
Returns
218+
-------
219+
output: af.Array
220+
Array containing the correlation coefficient of the input arrays.
221+
"""
105222
real = c_double_t(0)
106223
imag = c_double_t(0)
107224
safe_call(backend.get().af_corrcoef(c_pointer(real), c_pointer(imag), x.arr, y.arr))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /