Menu

[r5696]: / trunk / py4science / examples / pyrex / trailstats / movavg.pyx  Maximize  Restore  History

Download this file

56 lines (44 with data), 1.4 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
'''
This is kept as a module separate from pyringbuf so that the
latter does not depend on numpy.
'''
cimport c_numpy
import numpy
c_numpy.import_array()
include "c_ringbuf.pxi"
def runstats(data, nrb):
'''
Compute running stats on 1D array data for odd length nrb
'''
cdef c_numpy.ndarray c_data
cdef c_numpy.ndarray c_dmean
cdef c_numpy.ndarray c_dstd
cdef c_numpy.ndarray c_dmin
cdef c_numpy.ndarray c_dmax
cdef c_numpy.ndarray c_dmedian
cdef c_numpy.ndarray c_ng
data = numpy.asarray(data, dtype=numpy.float_)
if data.ndim != 1:
raise ValueError("data must be 1-D for now")
nd = data.shape[0]
dmean = numpy.empty_like(data)
dstd = numpy.empty_like(data)
dmin = numpy.empty_like(data)
dmax = numpy.empty_like(data)
dmedian = numpy.empty_like(data)
ng = numpy.empty(data.shape, dtype=numpy.int_)
c_data = data
c_dmean = dmean
c_dstd = dstd
c_dmin = dmin
c_dmax = dmax
c_dmedian = dmedian
c_ng = ng
c_runstats(nrb, nd, <double *>c_data.data,
<double *>c_dmean.data,
<double *>c_dstd.data,
<double *>c_dmin.data,
<double *>c_dmax.data,
<double *>c_dmedian.data,
<int *>c_ng.data)
return dmean, dstd, dmin, dmax, dmedian, ng
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.