2019-04-01から1ヶ月間の記事一覧
Problem You run an e-commerce website and want to record the last N order ids in a log. Implement a data structure to accomplish this, with the following API: record(order_id): adds the order_id to the log get_last(i): gets the i-th last e…
Problem Implement a stack that has the following method. push(val), which pushes an element onto the stack pop(), which pops off and returns the topmost element of the stack. If there are no elements in the stack, then it should throw an e…
Traceback (most recent call last): File "/home/usrname/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/traitlets/traitlets.py", line 528, in get value = obj._trait_values[self.name] KeyError: 'runtime_dir' During handling of …
conda等で複数の仮想環境を入れているときにjupyterでkernelを入れ替えたい 現在利用可能なkernelの確認 $ jupyter kernelspec list Available kernels: tensorflow /home/username/.local/share/jupyter/kernels/tensorflow tensorflow2 /home/username/.lo…
CentOS7.6を入れて、CUDAの環境を作るまでをまとめました。 1. CentOSを入れる CentOSの初期設定 2. NVIDIA driverのインストール 2.1 nouveauの無効化 2.2 NVIDIA-Linux-***-runのinstall uninstallするときは 注意 補足:パッケージマネージャーの使用 3 c…
アルゴリズム 数列を半分半分に分割していって並び替えたものを作る 順番を揃えつつmergeする 基本はこれだけ。最小分割単位1では何もしないこととmergeするときのアルゴリズムに注意する。 コード例 startはsortするはじめのindexで,endは最後のindex+1に…
問題 double型の0から1の実数を2進数表記する。 考え方 簡単な例として0.5は2進数では0.1とかける。 つまり、2倍して1のくらいが1になれば1を立てる。 コード例 #include<iostream> #include<string> using namespace std; string bitRep(double x){ string ans = "0."; wh</string></iostream>…
問題 最大32bit整数N, Mが与えられたときにNのjビット目からiビット目にMを挿入する。 考え方 Nのjからiビットを0に変えて、Mを挿入する 注意 ビットは0から数える。一番右が0ビット目。 コード例 #include<iostream> #include<bitset> using namespace std; unsigned int inse</bitset></iostream>…
$ sshfs usrname@hostname:/remote_path/ /local_path/ sshfsでは~を使うとエラーが出る。rootユーザーになるからとか書いてあった気がする。 $ sshfs usrname@hostname:~/remote_path/ /local_path/ fuse: invalid argument `~/remote_path/` のようなエラ…
余白をなくしたいとき 以下のように保存すると余計な余白が消える。 fig = plt.figure() ax = fug.add_subplot(111) # 略 plt.savefig("sample.pdf", bbox_inches="tight", pad_inches=0.05) 論文用にデータをプロットするとき plt.rcParams['mathtext.fonts…
OpenMPの並列計算で行列の同じ要素にアクセスするときに同時に書き換えるとデータが壊れる可能性がある。 atomicを使うとどれかのスレッドでアクセスしている際にその作業が終わるまで待つようになる。 何度も同じ要素にアクセする際には計算時間が遅くなる…
混乱するのでまとめました。 PGI 使い方 参考サイト 公式ページ その他 Intel Compiler 使い方 メモ 参考サイト その他 一般的なこと PGI 使い方 openmpで並列化するときはとりあえずはこれでいいはず。 でも、なぜか-mp指定しなくてもOpenMPのコンパイルが…
パイプで繋げるときは次のコマンドは!いらない。 例として、 !cat temp.txt | wc -l またawkを使うときには注意が必要で、{{, $$にする必要がある。 !cat temp.txt | awk '{{print $$1 " " $$2}}' ほんとはこの出力をそのままnp.loadtxtとかに渡したいけど、…
以下のようなテキストファイルの1列目の値でuniqueな個数を数える。 # sample.txt 41 83 83 186 88 186 989 187 494 210 98 225 以下のコマンドで重複しないで1列目の値だけを表示する。 cat sample.txt | awk `a[$1]++ == 0 {print $1}' 行の数を数えると…