Download this file

59 lines (48 with data), 1.7 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
import subprocess
import numpy as np
def sorted_slice(a,l,r):
start = np.searchsorted(a, l, 'left')
end = np.searchsorted(a, r, 'right')
return np.arange(start,end)
def meanOfCounter(counter):
sum_of_numbers = sum(
number * count for number,
count in counter.most_common())
count = sum(count for n, count in counter.most_common())
if count == 0:
return 0
return sum_of_numbers / count
def varianceOfCounter(counter):
sum_of_numbers = sum(
number * count for number,
count in counter.most_common())
if sum_of_numbers == 0:
return 0
count = sum(count for n, count in counter.most_common())
total_squares = sum(
number * number * count for number,
count in counter.most_common())
mean_of_squares = total_squares / count
mean = sum_of_numbers / count
variance = mean_of_squares - mean * mean
return math.sqrt(variance)
def wccount(filename):
out = subprocess.Popen(['wc', '-l', filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
).communicate()[0]
return int(out.partition(b' ')[0])
def wccountgz(filename):
try:
cmd = f'zcat {filename} | wc -l'
out = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True
).communicate()[0]
return int(out.partition(b' ')[0])
except Exception as e:
return 0