Source

pymissile / vector.py

Full commit
import math

from itertools import starmap, repeat
from operator import mul

def magnitude(v):
  return math.sqrt(sum(v[i]*v[i] for i in range(len(v))))

def add(u, v):
  return [ u[i]+v[i] for i in range(len(u)) ]

def sub(u, v):
  return [ u[i]-v[i] for i in range(len(u)) ]

def dot(u, v):
  return sum(u[i]*v[i] for i in range(len(u)))

def normalize(v):
  vmag = magnitude(v)
  return [ v[i]/vmag  for i in range(len(v)) ]

def mul_scalar(v, scalar):
  return list(starmap(mul, zip(v, repeat(scalar))))