Remrinのpython攻略日記

python3に入門しました。python3についてあれこれとサンプルコードとか。

2017-05-11から1日間の記事一覧

NumPyの使い方(6) 条件制御

NumPyの条件制御について。 if~elseで条件分岐をするとき a = 5 if a >= 0: b = 1 else: b = -1 と書けますが、これを3項演算子を使い以下のようにも書けます。 b = 1 if a >= 0 else -1 似たような動作を組み込みのリスト型で行うとき、 例えば、Trueなら…

NumPyの使い方(5) ベクトル演算とユニバーサル関数

ベクトル演算とユニバーサル関数について。 ベクトル演算 ndarrayと数値(スカラー)の計算は全要素対象で、forループを使わない。 ndarrayどうしの演算は対応する位置の要素どうしで計算。 [注意]ndarray * ndarrayは内積や外積にはならない。 import numpy a…

Project Euler

Project Euler problem #001 Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. 問題1…