pf-3. 計算誤差,データの種類

>100 Views

January 29, 23

スライド概要

トピックス:Python, Google Colaboratory, 計算誤差, データの種類, type

Python 入門(Google Colaboratory を使用)(全8回)
https://www.kkaneko.jp/pro/pf/index.html

金子邦彦研究室ホームページ
https://www.kkaneko.jp/index.html

profile-image

金子邦彦(かねこくにひこ) 福山大学・工学部・教授 ホームページ: https://www.kkaneko.jp/index.html 金子邦彦 YouTube チャンネル: https://youtube.com/user/kunihikokaneko

シェア

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

pf-3. 計算誤差,データの種類 (Python 入門,Google Colaboratory を使用) (全8回) URL: https://www.kkaneko.jp/pro/pf/index.html 金子邦彦 1

2.

計算誤差 コンピュータの計算は,完璧に正確というわけでは ない.誤差を含む場合がある 1 ÷ 3 の計算 0.0000000000000000333333 333333333333333333333333 33333... が誤差! 2

3.

データの種類 • 文字データ • 数値データ • その他 3

4.

Python の主なデータの種類 データの種類 クラス名 int 整数 浮動小数 Python プログラムでの書き方 10 Decimal import decimal decimal.Decimal(10) float 1.23 complex 文字列 str "Hello, World\n" true/false 日時 bool True datetime.datetime import datetime as dt dt.datetime(2022, 12, 1, 1, 23, 45) リスト List [1, 2, 3] レンジ range range(1, 4) 辞書 dict {1: "orange", 2: "apple", 3: "apple"} numpy 配列 numpy.ndarray import numpy as np np.array([1, 2, 3]) 4

5.

Python でのクラスの取得 Python では,type を用いてクラスを取得できる 5

6.

演習 資料:7 ~ 11 【トピックス】 • 計算誤差 • クラス 6

7.

① Google Colaboratory のWebページを開く https://colab.research.google.com 7

8.

② 「ファイル」で,「ノートブックを新規作成」を選ぶ ③ Google アカウントでのログインが求められたときはログ インする 8

9.

④ コードセルを新規作成し,Python プログラムを入れる print(1/3) すべて半角文字 ⑤ 実行結果を確認 9

10.

面積が 7 の正方形の一辺の長さを得る.(Python の math を利用) ⑥ コードセルを新規作成し,Python プログラムを入れる import math print( math.sqrt(7) ) ⑦ 実行結果を確認 (結果は近似値) 10

11.

半径 3 の円の面積を得る.(円周率は, Python の math を使用) ⑧ コードセルを新規作成し,Python プログラムを入れる import math print( 3 * 3 * math.pi ) ⑨ 実行結果を確認 (結果は近似値) 11

12.

三角形の2辺の長さが,4と6で,その間の角度が60 度のとき, 面積は (1/2) × 4 × 6 × sin(60) ⑩ コードセルを新規作成し,Python プログラムを入れる import math print( (1/2) * 4 * 6 * math.sin(60 * math.pi / 180) ) ⑪ 実行結果を確認 12

13.

⑫ コードセルを新規作成し,Python プログラムを入れる b = 10 print(type(b)) ⑬ 実行結果を確認 13

14.

⑭ コードセルを新規作成し,Python プログラムを入れる x = 1.2 print(type(x)) ⑮ 実行結果を確認 14

15.

オペレーティングシステム(コンピュータ)のタイ マーを使いたい.(Python の datetime を利用) ⑯ コードセルを新規作成し,Python プログラムを入れる import datetime now = datetime.datetime.now() print(now) print(type(now)) ⑰ 実行結果を確認 15

16.

Python 関連ページ • Python まとめページ https://www.kkaneko.jp/tools/man/python.html • Python プログラミングの基本 Python Tutor, VisuAlgo, Code Combat を使用 https://www.kkaneko.jp/pro/po/index.html • Python プログラム例 https://www.kkaneko.jp/pro/python/index.html • 人工知能の実行(Google Colaboratory を使用) https://www.kkaneko.jp/ai/ni/index.html • 人工知能の実行(Python を使用)(Windows 上) https://www.kkaneko.jp/ai/deepim/index.html 16