FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arrayfire-python/arrayfire/statistics.py at v3.5 · arrayfire/arrayfire-python · GitHub
arrayfire
arrayfire-python
Repository navigation
Code
Issues
57
(57)
Pull requests
3
(3)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
arrayfire-python
/
arrayfire
/
statistics.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
110 lines (92 loc) · 3.49 KB
Breadcrumbs
arrayfire-python
/
arrayfire
/
statistics.py
Copy path
File metadata and controls
110 lines (92 loc) · 3.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#######################################################
# Copyright (c) 2015, 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
########################################################
"""
Statistical algorithms (mean, var, stdev, etc).
"""
from
.
library
import
*
from
.
array
import
*
def
mean
(
a
,
weights
=
None
,
dim
=
None
):
if
dim
is
not
None
:
out
=
Array
()
if
weights
is
None
:
safe_call
(
backend
.
get
().
af_mean
(
c_pointer
(
out
.
arr
),
a
.
arr
,
c_int_t
(
dim
)))
else
:
safe_call
(
backend
.
get
().
af_mean_weighted
(
c_pointer
(
out
.
arr
),
a
.
arr
,
weights
.
arr
,
c_int_t
(
dim
)))
return
out
else
:
real
=
c_double_t
(
0
)
imag
=
c_double_t
(
0
)
if
weights
is
None
:
safe_call
(
backend
.
get
().
af_mean_all
(
c_pointer
(
real
),
c_pointer
(
imag
),
a
.
arr
))
else
:
safe_call
(
backend
.
get
().
af_mean_all_weighted
(
c_pointer
(
real
),
c_pointer
(
imag
),
a
.
arr
,
weights
.
arr
))
real
=
real
.
value
imag
=
imag
.
value
return
real
if
imag
==
0
else
real
+
imag
*
1j
def
var
(
a
,
isbiased
=
False
,
weights
=
None
,
dim
=
None
):
if
dim
is
not
None
:
out
=
Array
()
if
weights
is
None
:
safe_call
(
backend
.
get
().
af_var
(
c_pointer
(
out
.
arr
),
a
.
arr
,
isbiased
,
c_int_t
(
dim
)))
else
:
safe_call
(
backend
.
get
().
af_var_weighted
(
c_pointer
(
out
.
arr
),
a
.
arr
,
weights
.
arr
,
c_int_t
(
dim
)))
return
out
else
:
real
=
c_double_t
(
0
)
imag
=
c_double_t
(
0
)
if
weights
is
None
:
safe_call
(
backend
.
get
().
af_var_all
(
c_pointer
(
real
),
c_pointer
(
imag
),
a
.
arr
,
isbiased
))
else
:
safe_call
(
backend
.
get
().
af_var_all_weighted
(
c_pointer
(
real
),
c_pointer
(
imag
),
a
.
arr
,
weights
.
arr
))
real
=
real
.
value
imag
=
imag
.
value
return
real
if
imag
==
0
else
real
+
imag
*
1j
def
stdev
(
a
,
dim
=
None
):
if
dim
is
not
None
:
out
=
Array
()
safe_call
(
backend
.
get
().
af_stdev
(
c_pointer
(
out
.
arr
),
a
.
arr
,
c_int_t
(
dim
)))
return
out
else
:
real
=
c_double_t
(
0
)
imag
=
c_double_t
(
0
)
safe_call
(
backend
.
get
().
af_stdev_all
(
c_pointer
(
real
),
c_pointer
(
imag
),
a
.
arr
))
real
=
real
.
value
imag
=
imag
.
value
return
real
if
imag
==
0
else
real
+
imag
*
1j
def
cov
(
a
,
isbiased
=
False
,
dim
=
None
):
if
dim
is
not
None
:
out
=
Array
()
safe_call
(
backend
.
get
().
af_cov
(
c_pointer
(
out
.
arr
),
a
.
arr
,
isbiased
,
c_int_t
(
dim
)))
return
out
else
:
real
=
c_double_t
(
0
)
imag
=
c_double_t
(
0
)
safe_call
(
backend
.
get
().
af_cov_all
(
c_pointer
(
real
),
c_pointer
(
imag
),
a
.
arr
,
isbiased
))
real
=
real
.
value
imag
=
imag
.
value
return
real
if
imag
==
0
else
real
+
imag
*
1j
def
median
(
a
,
dim
=
None
):
if
dim
is
not
None
:
out
=
Array
()
safe_call
(
backend
.
get
().
af_median
(
c_pointer
(
out
.
arr
),
a
.
arr
,
c_int_t
(
dim
)))
return
out
else
:
real
=
c_double_t
(
0
)
imag
=
c_double_t
(
0
)
safe_call
(
backend
.
get
().
af_median_all
(
c_pointer
(
real
),
c_pointer
(
imag
),
a
.
arr
))
real
=
real
.
value
imag
=
imag
.
value
return
real
if
imag
==
0
else
real
+
imag
*
1j
def
corrcoef
(
x
,
y
):
real
=
c_double_t
(
0
)
imag
=
c_double_t
(
0
)
safe_call
(
backend
.
get
().
af_corrcoef
(
c_pointer
(
real
),
c_pointer
(
imag
),
x
.
arr
,
y
.
arr
))
real
=
real
.
value
imag
=
imag
.
value
return
real
if
imag
==
0
else
real
+
imag
*
1j
Back
|
FazBrowse Home
|
New Git URL