ユーザ用ツール

サイト用ツール


プログラム:python

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
プログラム:python [2024/11/29 09:28]
kawaue
プログラム:python [2025/08/14 09:23] (現在)
kawaue
行 102: 行 102:
 from hoge import Hoge from hoge import Hoge
 </file> </file>
 +
 +===関数===
 +以下のように宣言する。返り値を複数設定可能で、配列で渡される。
 +<file>
 +def hoge(huga,piyo):
 +    foo = huga + piyo
 +    bar = huga - piyo
 +    return foo, piyo
 +</file>
 +配列の各要素に関数を作用させたいとき\\
 +例:shapeが(1000,2)のnumpy.array num_arrayの二つ目の軸の要素の和と差のnumpu.arrayを作りたい
 +<file>
 +new_array = np.apply_along_axis(lambda element: hoge(*element), 1, num_array)
 +</file>
 +lambda : ラムダ式。ここでだけ使う関数を宣言できる。
  
 ===クラス=== ===クラス===
行 137: 行 152:
 ''range(start,stop,step)''は$\mathrm{start}\leqq i<\mathrm{stop}$の間で''step''ずつカウンターを増やす。 ''range(start,stop,step)''は$\mathrm{start}\leqq i<\mathrm{stop}$の間で''step''ずつカウンターを増やす。
  
-===関数など===+===組み込み関数など===
 type() : 型を表示する。 type() : 型を表示する。
  
行 166: 行 181:
  
 a=value of each bin, b=bin a=value of each bin, b=bin
 +
 +====2軸plot====
 +<code>
 +run_index = 0
 +fig, ax1 = plt.subplots()
 +ax2 = ax1.twinx()
 +ax2.plot(histories2[run_index].history['lr'],label='learning rate',linestyle='--',color='green')
 +ax1.plot(histories2[run_index].history['loss'],label='training loss')
 +ax1.plot(histories2[run_index].history['val_loss'],label='validation loss')
 +plt.title('1st iteration, step 1, batch : 8192 lr : 1e-6, 1st trials')
 +ax1.set_xlabel('epoch')
 +ax1.set_ylabel('Loss')
 +ax2.set_ylabel('Learning Rate')
 +handler1, label1 = ax1.get_legend_handles_labels()
 +handler2, label2 = ax2.get_legend_handles_labels()
 +ax1.legend(handler1 + handler2, label1 + label2)
 +#plt.legend()
 +plt.figure()
 +</code>
 +
 ====機械学習==== ====機械学習====
 ===tensorflow=== ===tensorflow===
プログラム/python.1732872530.txt.gz · 最終更新: 2024/11/29 09:28 by kawaue