「 未分類 」 一覧

no image

python3 で辞書(dict) の for ループでキーと値を取得する

2020/11/20   -未分類

キーと値を取得するには次のようにする。キーは dict のループ、値は dict の values() のループで取得できる。 例 mydictionary = {‘color’: ‘白’, ‘ani …

no image

matplotlib で x, y軸・タイトルのフォントサイズを調整する

2020/11/18   -未分類

ラベルの fontsize で指定する。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2, 100) …

no image

python3 で数字をゼロ埋めして表示する

2020/11/18   -未分類

string の、zfill を使う。 例 n = 3 n0 = str(n).zfill(10) print(n0) 結果 0000000003

no image

python3 でリストの偶数番目・奇数番目の項目を出力する

2020/11/18   -未分類

リストに対して、::2 を使えば良い。 例 list1 = [‘日’,’月’,’火’,’水’,’木’,’金’,’土’] list2 = list1[::2] list3 = list1[1::2] p …

no image

python3 で文字列のリストを結合して1つの文字列にする方法

2020/11/18   -未分類

リストに対して、join メソッドを実行する。 例 list1 = [‘hello, ‘,’good ‘, ‘morning’] str1 = ”.join(list1) print(str1) 結 …

no image

tex で図の番号を表示しない方法

2020/11/17   -未分類

caption パッケージを使っておき、\caption* を使うと、図の番号を表示しないようにできる。 例 \usepackage{caption} \begin{document} \begin{ …

no image

tex で数式モード内に普通の文字列を入力する方法

2020/11/17   -未分類

\textrm を使う。 例 $$y = f (x) \hspace{1cm} \textrm{This is a function.}$$ 結果

no image

tex で文字列を変数として設定する方法

2020/11/17   -未分類

\newcommand を使って指定する。入力の数は自由に指定できる。 例 \newcommand{\variable}[2]{Hello #1. Good #2.} \variable{Taro}{ …

no image

matplotlib で縦横の罫線を出力する

2020/11/17   -未分類

罫線を出力するには、pyplot.grid を使う。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 …

no image

python3 で、ファイルの文字列の1行目を出力する

2020/11/17   -未分類

ファイルを読み込んで、1行目だけをコンソールに出力するには readlines() を使う。 例 f = open(“data.txt”) lines = f.readlines() print(li …