PriorityQueueの確認
PriorityQueueをPythonで表してみる。
こんなんで大きい順に出せるのかと思った。
class PriorityQueue(object): def __init__(self): self.l = [] def push(self, x): self.l.append(x) sz = len(self.l) i = sz - 1 while i > 0: p = (i - 1) // 2 if self.l[p] >= x: break self.l[i] = self.l[p] i = p self.l[i] = x def pop(self): sz = len(self.l) if sz == 0: return None res = self.l[0] x = self.l[-1] i = 0 while (i * 2 + 1) < sz: a = i * 2 + 1 b = i * 2 + 2 if b < sz and self.l[b] > self.l[a]: a = b if self.l[a] <= x: break self.l[i] = self.l[a] i = a self.l[i] = x self.l = self.l[:-1] return res
In [91]: a = PriorityQueue() In [92]: a.push(2) In [92]: a.push(2) In [93]: a.push(2) In [94]: a.push(4) In [95]: a.push(5) In [96]: a.push(20) In [97]: a.push(215) In [98]: a.push(23) In [99]: a.push(12) In [100]: a.l Out[100]: [215, 12, 23, 5, 4, 2, 20, 2] In [101]: a.pop() Out[101]: 215 In [102]: a.pop() Out[102]: 23 In [103]: a.pop() Out[103]: 20 In [104]: a.pop() Out[104]: 12 In [105]: a.pop() Out[105]: 5 In [106]: a.pop() Out[106]: 4 In [107]: a.pop() Out[107]: 2 In [108]: a.pop() Out[108]: 2 In [109]: a.pop()
最長共通部分問題のPythonで記述
最長共通部分問題について、pythonで解いてみた。 もしかしたら、間違っているかも
class LCS(object): def __init__(self, s, t): self.s = s self.t = t self.n = len(s) self.m = len(t) self.dp = [[-1 for mm in range(self.m + 1)] for nn in range(self.n + 1)] def solve(self, i, j): if self.dp[i][j] >= 0: return self.dp[i][j] if i == 0 or j == 0: return 0 if self.s[i - 1] == self.t[j - 1]: self.dp[i][j] = max(self.solve(i - 1, j - 1) + 1, self.solve(i, j - 1), self.solve(i - 1, j)) else: self.dp[i][j] = max(self.solve(i, j-1), self.solve(i-1, j)) res = self.dp[i][j] return res def get_lcs(self): return self.solve(self.n, self.m)
In [53]: lcs = LCS('abcd', 'becd') In [54]: lcs.get_lcs() Out[54]: 3
レビューの星の計算方法
最低投票数の閾値の割合 × 全ての投票の☆平均値 + ターゲットの投票数の割合 × ターゲットの☆平均値
(WR) = (v / (v+m)) × R + (m / (v+m)) × C = (v × R + m × C) / (v+m) * R = 対象の☆の数の平均 * v = 投票数 * m = 最低投票数閾値 * C = 全ての☆の数の平均
pip freezeの結果
pip freezeの結果
asn1crypto==0.22.0 beautifulsoup4==4.6.0 bleach==2.0.0 certifi==2017.4.17 cffi==1.10.0 chardet==3.0.4 click==6.7 cryptography==1.9 cycler==0.10.0 decorator==4.0.11 dj-database-url==0.4.2 Django==1.11.2 django-bootstrap-form==3.3 entrypoints==0.2.3 first==2.0.1 future==0.16.0 gunicorn==19.7.1 html5lib==0.999999999 idna==2.5 ipykernel==4.6.1 ipython==6.1.0 ipython-genutils==0.2.0 ipywidgets==7.0.0 jedi==0.10.2 Jinja2==2.9.6 jsonschema==2.6.0 jupyter==1.0.0 jupyter-client==5.1.0 jupyter-console==5.2.0 jupyter-core==4.3.0 line-bot-sdk==1.5.0 lxml==3.8.0 MarkupSafe==1.0 matplotlib==2.0.2 mecab-python3==0.7 mistune==0.7.4 nbconvert==5.2.1 nbformat==4.4.0 notebook==5.0.0 numpy==1.13.1 pandas==0.20.3 pandocfilters==1.4.2 pew==0.1.26 pexpect==4.2.1 pickleshare==0.7.4 pip-tools==1.9.0 pipenv==7.2.6 prompt-toolkit==1.0.14 psycopg2==2.7.3.1 ptyprocess==0.5.2 pycparser==2.17 Pygments==2.2.0 PyMySQL==0.7.11 pyOpenSSL==17.1.0 pyparsing==2.2.0 python-dateutil==2.6.1 pythonz-bd==1.11.4 pytz==2017.2 pyzmq==16.0.2 qtconsole==4.3.1 requests==2.18.1 resumable-urlretrieve==0.1.5 scikit-learn==0.19.0 scipy==1.0.0 seaborn==0.8.1 semver==2.7.8 simplegeneric==0.8.1 six==1.10.0 terminado==0.6 testpath==0.3.1 tornado==4.5.1 traitlets==4.3.2 typing==3.6.1 urllib3==1.21.1 virtualenv==15.1.0 virtualenv-clone==0.2.6 wcwidth==0.1.7 webencodings==0.5.1 whitenoise==3.3.0 widgetsnbextension==3.0.2
asn1crypto beautifulsoup4 bleach certifi cffi chardet click cryptography cycler decorator dj-database-url Django django-bootstrap-form entrypoints first future gunicorn html5lib idna ipykernel ipython ipython-genutils ipywidgets jedi Jinja2 jsonschema jupyter jupyter-client jupyter-console jupyter-core lxml MarkupSafe matplotlib mecab-python3 mistune nbconvert nbformat notebook numpy pandas pandocfilters pew pexpect pickleshare pip-tools pipenv prompt-toolkit psycopg2 ptyprocess pycparser Pygments PyMySQL pyOpenSSL pyparsing python-dateutil pythonz-bd pytz pyzmq qtconsole requests resumable-urlretrieve scikit-learn scipy seaborn semver simplegeneric six terminado testpath tornado traitlets typing urllib3 virtualenv virtualenv-clone wcwidth webencodings whitenoise widgetsnbextension
topコマンドで別々のCPUの稼働状況確認する
$ top # "1"をpush top - 16:11:38 up 4 days, 17:22, 2 users, load average: 1.00, 0.99, 0.78 Tasks: 177 total, 3 running, 174 sleeping, 0 stopped, 0 zombie %Cpu0 : 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu1 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu2 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu3 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu4 : 98.7 us, 1.3 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu5 : 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu6 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu7 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 30716876 total, 3970456 free, 15388480 used, 11357940 buff/cache KiB Swap: 0 total, 0 free, 0 used. 14824368 avail Mem