numpyの演算
numpyの演算は、二次元の配列と一次元の配列を明確に区別している。
一次元の配列はvectorとして、二次元の配列はmatrixとして、数学的に許された演算のみ可能。
例えば、[0 1 2 3 4 5]
と[[0 1 2 3 4 5]]
の演算はできない。
def printVar(var, symboltable): for k, v in symboltable.items(): if id(v) == id(var): print("{0}:".format(k)) print(v) print("") a = np.arange(6) row_mat = np.arange(6).reshape(1, -1) row_mat_trans = row_mat.T col_mat = np.arange(6).reshape(-1, 1) col_mat_trans = col_mat.T add_mat = row_mat + col_mat_trans mult_mat = row_mat.dot(col_mat) printVar(a, locals()) printVar(row_mat, locals()) printVar(row_mat_trans, locals()) printVar(col_mat, locals()) printVar(col_mat_trans, locals()) printVar(add_mat, locals()) printVar(mult_mat, locals()) # operations causing errors # mult_mat = a.dot(row_mat)
出力は
a: [0 1 2 3 4 5] row_mat: [[0 1 2 3 4 5]] row_mat_trans: [[0] [1] [2] [3] [4] [5]] col_mat: [[0] [1] [2] [3] [4] [5]] col_mat_trans: [[0 1 2 3 4 5]] add_mat: [[ 0 2 4 6 8 10]] mult_mat: [[55]]
有限体の勉強するのに良い本
finite fields - Books on advanced galois theory - MathOverflow より引用。
- Amazon.co.jp: Finite Fields (Encyclopedia of Mathematics and its Applications): Rudolf Lidl, Harald Niederreiter: 洋書
- Amazon.co.jp: Introduction to Finite Fields and their Applications: Rudolf Lidl, Harald Niederreiter: 洋書
- Finite Fields and Applications (Student Mathematical Library): Gary L. Mullen, Carl Mummert: 9780821844182: Amazon.com: Books
Sierraのkarabiner elementsで日本語キーボードをUSキーボードっぽく使う
KarabinerはSierraにまだ対応していない。 Karabiner elementsでキーボードの配列を変更できるので、キーボードの配列を一文字ずついじってUSっぽく使うことはできる。
~/.config/karabiner/karabiner.json
にキーの設定ファイルがあるので、以下を追記する。
Karabiner-Elements/README.md at master · tekezo/Karabiner-Elements
"simple_modifications": { "0": "9", "1": "grave_accent_and_tilde", "2": "1", "3": "2", "4": "3", "5": "4", "6": "5", "7": "6", "8": "7", "9": "8", "caps_lock": "fn", "delete_forward": "equal_sign", "equal_sign": "hyphen", "hyphen": "0", "international1": "backslash", "international3": "equal_sign" },
次にKarabiner-Elementsを開きVirtual Keyboard
のタブのKeyboard typeをANSI
にしておく。
参考
std::stringでtolower/toupper
#include <algorithm> #include <string> std::string data = "Abc"; std::transform(data.begin(), data.end(), data.begin(), ::tolower); std::transform(data.begin(), data.end(), data.begin(), ::toupper);
Reference
MathJaxでQED記号をかく
MathJaxで証明終了の記号をかく。
記号自体は\Box
で与えられるが、右寄せにhtmlタグを使う必要がある。
<div class="QED" style="text-align: right">$\Box$</div>
class="QED"
は特に意味がないので、消しても良い。
Travis CIでビルドの回数を抑える時
C++の場合は、一回のビルド・テストに非常に時間がかかるので、ビルドを減らしたい場合がある。 Travis CIでは、設定で
Build pushs
- push時にビルド
Build pull requests
- pull request 時にビルド
がある。 両方ONにすると、PR時に2回ビルドが走ることになる。 Travis CIの場合この2回のビルドは同じビルドではないが、PRのビルドだけ通れば十分である場合が多い。 以下のような設定を実現する方法を記載する。
- PRでのbranchは全てビルド
- pushでのビルドはmaster branchのみ
単純にBuild pushs
をoffにすると、merge後のmaster
のビルドが行われずに、badgeが更新されない。
補足
PRのビルドはmaster
branchへのmerge後のビルドをしているので、pushのビルドとは異なる。
Travis CIが裏でmergeのコミットを作成し、ビルドしている。
方法
Travis CIの設定から以下をONにする。
Build pushs
Build pull requests
.travis.yml
に以下を記載する。
branches: only: # branchs through PR are built - master