[ edit ]

# ===== 関数定義: 内積(ドット積)を求めます =====
def dot_product( v1, v2 ):
    n = len( v1 )
    p = 0.0;
    for i in range( n ):
        p += ( v1[i] * v2[i] )
    return( p )

# ===== 関数定義: ベクトルの入力を受け付けます =====
def input_vector( message ):
    data_str = input( message )
    str_tuple = data_str.split( "," )
    float_list = list()
    for s in str_tuple:
        float_list.append( float( s ) )
    v = tuple( float_list )
    return( v )

SoftEng: Python/Prog/Example/04/Ex_004a/Digest (last edited 2018-10-29 18:52:06 by TadashiIijima)