math




組み込み関数

# 1 abs( -1 ) # 商とあまりを返す d, m = divmod( 10, 3 ) # 1024 pow( 2, 10 ) # 1 round( 1.23 ) # 小数第一位 # 1.2 round( 1.23, 1 )



標準ライブラリ

import math; math.cos( math.pi ); math.sin( math.pi ); math.degrees( math.pi ) math.radians( math.pi ) import random # [0:1) random.random() WARNING # ++ がないかもしれない i = 0 i += 1



numeric(数値演算)

REF http://pypi.python.org/pypi/Numeric/24.2(numeric) ベクトル
v = numpy.array( (2.0, 2.0, 1.0) ) # ノルム l = numpy.linalg.norm(v) # 内積 外積 numpy.dot(v1,v2) numpy.cross(v1,v2)
行列
m = numpy.matrix( ( (2.0, 0.0, 10), (0.0, 3.0, 10), (0.0, 3.0, 10), ) ) # 逆行列, 転置 print ( a.I ) print ( a.T ) # 行列式 numpy.linalg.det(a) # 行列とベクトルの積 ret = numpy.dot(mat,v) # 行列の積 ret = m * m;