Tokyo.SciPy #2 にて発表した、数式(あるいは数式入りのアルゴリズム)から実装に落とす場合、何に気をつけるのか、どう考えればいいのか、というお話。 対象は、どうやって数式をプログラムすればいいかよくわからない人、ちょっとややこしい数式になると四苦八苦してしまい、コードに落とすのにすごく時間がかかってしまう人、など。 ここでは実行速度についてはひとまずおいといて、簡潔で間違いにくい、ちゃんと動くコードを書くことを目標にしています。
Pythonで一番有名で普及しているライブラリと言っても過言ではない「Numpy」の覚書きです。かなり多機能な数値計算ライブラリで、内部はC言語で記述されているため超高速に動作します。 ベクトル ベクトルの長さ&正規化 import numpy a = numpy.array([[2,2]]) #ベクトルの長さ length = numpy.linalg.norm(a) #length=>2.8284271247461903 #ベクトルの正規化 a / numpy.linalg.norm(a) #=>array([[ 0.70710678, 0.70710678]]) 内積&外積 import numpy v1 = numpy.array((1,0,0)) v2 = numpy.array((0,1,0)) #内積 numpy.dot(v1,v2) #=> 0 #外積 numpy.cros
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く