このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
priv:python [2022/02/25 10:57] – ↷ python から priv:python へページを移動しました。 admin | priv:python [2022/08/17 01:09] (現在) – admin | ||
---|---|---|---|
行 1: | 行 1: | ||
===== Python ===== | ===== Python ===== | ||
+ | |||
+ | === ソースコードの難読化 === | ||
+ | * [[https:// | ||
+ | |||
+ | === 相関係数 === | ||
+ | <code python> | ||
+ | import pandas as pd | ||
+ | import numpy as np | ||
+ | l1=list(np.random.randint(0, | ||
+ | l2=list(np.random.randint(0, | ||
+ | s1=pd.Series(l1) | ||
+ | s2=pd.Series(l2) | ||
+ | res=s1.corr(s2) | ||
+ | print(res) | ||
+ | </ | ||
+ | |||
+ | === よくあるパターン === | ||
面倒なのでよくあるパターンを列挙します。 | 面倒なのでよくあるパターンを列挙します。 | ||
+ | <code python> | ||
+ | # | ||
+ | # -*- coding: | ||
+ | # | ||
+ | |||
+ | from sudachipy import tokenizer | ||
+ | from sudachipy import dictionary | ||
+ | |||
+ | def wakati( sentence ): | ||
+ | mode = tokenizer.Tokenizer.SplitMode.C | ||
+ | return " " | ||
+ | |||
+ | simplified_file = open(' | ||
+ | |||
+ | original_sep = [] | ||
+ | simplified_sep = [] | ||
+ | tokenizer_obj = dictionary.Dictionary().create() | ||
+ | |||
+ | with open(' | ||
+ | for original_line in original_file: | ||
+ | original_line = original_line.strip() | ||
+ | simplified_line = simplified_file.readline().strip() | ||
+ | |||
+ | original_sep.append(wakati(original_line)) | ||
+ | simplified_sep.append(wakati(simplified_line)) | ||
+ | |||
+ | for i in range(0, len(original_sep)): | ||
+ | if i % 100 == 0: | ||
+ | outfile = open(' | ||
+ | |||
+ | print(i, file=outfile) | ||
+ | print(original_sep[i], | ||
+ | print(simplified_sep[i], | ||
+ | |||
+ | if i % 100 == 99: | ||
+ | outfile.close() | ||
+ | |||
+ | </ | ||