python 入門のページ一覧

slide-thumbnail
8.3 Python のプログラム構造 エラーへの対処 : try-except エラー(例外)が起こりえるコードを try 以下のブロックで記述 例外の典型例 ゼロ除算 : ZeroDivisionError 変数の型変換エラー : ValueError ファイル...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P17

slide-thumbnail
8.3 Python のプログラム構造 エラーへの対処を行うプログラムの例 import sys while True: x = input('Enter positive number: ') try: x = float(x) except ValueError: print(f'{x} ') continue except: print...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P18

slide-thumbnail
8.3 Python 実行例 のプログラム構造 Enter positive number: -1 -1.0 Enter positive number: abc abc Enter positive number: 3 3.0 は正の数値ではありません. は数値に変換できません. 19

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P19

slide-thumbnail
8.3 Python 関数 def のプログラム構造 関数名(引数1, 引数2,...): のあとに改行,次の行からブロックを記述 関数外部で定義されたグローバル変数は,関数内では参照のみ可能 変更可能にするためには global 宣...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P20

slide-thumbnail
8.3 Python のプログラム構造 関数を用いたプログラムの例 import sys def input_number(): while True: x = input('Enter positive number: ') try: x = float(x) except ValueError: print(f'{x} ') continue e...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P21

slide-thumbnail
8.3 Python のプログラム構造 def square_root(x): rnew = x while True: r1 = rnew r2 = x/r1 rnew = (r1 + r2)/2 if r1 - r2 < 1.0E-6: break return rnew x = input_number() sq = square_root(x) print(f'Squa...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P22

slide-thumbnail
8.3 Python のプログラム構造 デフォルト引数を持つ関数定義の例と呼び出し方 def square_root(x, eps=1.0E-6): rnew = x while True: r1 = rnew r2 = x/r1 rnew = (r1 + r2)/2 if r1 - r2 < eps: break return rn...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P23

slide-thumbnail
8.3 Python クラス class のプログラム構造 クラス名(親クラス): のあとに改行,次の行からブロックを記述 ブロック内は冒頭にコンストラクタを定義し,その後にメソッドを定義 冒頭部にはクラス変数を定義する...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P24

slide-thumbnail
8.3 Python のプログラム構造 スタックをクラスとして定義する例 class MyStack(): def __init__(self, data): self.num_list = data def push(self, elem): self.num_list.append(elem) def pop(self): if self....

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P25

slide-thumbnail
8.3 Python のプログラム構造 if __name__ == '__main__': st = MyStack([5, 2, 3]) print(st.pop()) print(st.pop()) st.push(8) st.push(9) print(st.pop()) print(st.pop()) print(st.pop()) print(st.pop()) 3...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P26

slide-thumbnail
8.3 Python データクラス のプログラム構造 デコレータを付けて宣言する Java の Recod のように,コンストラクタや表示用のメソッドなどが自動生 成される frozen=True でイミュータブルなクラスになる @datacla...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P27

slide-thumbnail
8.3 Python のプログラム構造 ミックスイン Python では多重継承が可能 クラス定義時に,継承する親クラスをカンマで区切って列挙する 複数のクラスを継承して機能を追加することができる 典型的なミックスインの...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P28

slide-thumbnail
8.3 Python のプログラム構造 ファイル入出力 open() でファイル名とモードを指定して,返却値でファイルオブジェクト を得る モードは 'r' が読み込み, 'w' が書き込み 内容の読み込みメソッドは read() (全体)...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P29

slide-thumbnail
8.3 Python のプログラム構造 ファイルからデータを読み込む例 from dataclasses import dataclass @dataclass(frozen=True) class Student(): score: int name: str def read_data(filename): with open(filenam...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P30

slide-thumbnail
8.3 Python のプログラム構造 data = read_data('data.csv') for d in data: print(f'name: {d.name:<9} score: {d.score}') name: Alice name: Bob name: Caroline name: David name: Eve score: 80 score: 65 s...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P31

slide-thumbnail
8.4 Python のエコシステム ライブラリ 数値計算 Numpy グラフ描画 matplotlib データ操作 pandas, Polars 科学計算 scipy 機械学習 scikit-learn 深層学習 Keras, Tensorflow, PyTorch 32

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P32

slide-thumbnail
8.4 Python のエコシステム の科学技術計算ライブラリ Python 33

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P33

slide-thumbnail
8.4 Python のエコシステム 機械学習ライブラリの事例 : scikit-learn 分析・識別・回帰などの多くのアルゴリズムを提供 使用するクラスの選択基準 Start データ数が50以上 YES クラスを予測 YES NO NO も...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P34

slide-thumbnail
8.4 Python のエコシステム を使った教師あり学習のコード例 scikit-learn from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.linear_model import L...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P35

slide-thumbnail
8.4 Python のエコシステム ロジスティック回帰モデルの学習 # model = LogisticRegression() model.fit(X_train, y_train) テストデータでの予測 # y_pred = model.predict(X_test) モデルの性能評価 # accu...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P36

slide-thumbnail
8.4 Python のエコシステム 教師あり学習の手順 iris data f1 f2 f3 f4 class 5.1 3.5 1.4 0.2 setosa 4.9 3.0 1.4 0.2 setosa 5.7 2.8 4.1 1.3 versicolor 6.3 3.3 6.0 2.5 virginica...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P37

slide-thumbnail
8.4 Python のエコシステム Project Jupyter さまざまなプログラミング言語に対応したオープンソースソフトウェア・オ ープンスタンダード・サービスを開発することを目的として設立 JupyterLab 統合的な開発環...

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P38

slide-thumbnail
8.4 Python のエコシステム Google Colaboratory Jupyter notebook をオンラインで実行するサービス 40

プログラミング〈新〉作法 8. Python: スクリプト言語からエコシステムへの#P40