Since our vectors are dictionaries, lets convert them to lists for easier mathing.
199625
def cosine_sim(vec1, vec2):
    
    vec1 = [val for val in vec1.values()]
    vec2 = [val for val in vec2.values()]
    
    dot_prod = 0
    for i, v in enumerate(vec1):
        dot_prod += v * vec2[i]
        
    mag_1 = math.sqrt(sum([x**2 for x in vec1]))
    mag_2 = math.sqrt(sum([x**2 for x in vec2]))
    
    return dot_prod / (mag_1 * mag_2)
970840
def to_d(l):
    
    _d = {}
    for x in l:
        for k, v in x.items():
            _d[k] = v
    return _d
249075
def _dict_value_to_pairs(d):
    
    d = d[tz.first(d)]

    for k, v in d.items():
        yield {k: v}
517773
def _bunchify(b):
    """"""
    assert isinstance(b, dict)
    b = Bunch(b)
    for k in b:
        if isinstance(b[k], dict):
            b[k] = Bunch(b[k])
    return b
866910
def process_lists(self):
        """"""
        for l1_idx, obj1 in enumerate(self.l1):
            for l2_idx, obj2 in enumerate(self.l2):
                if self.equal(obj1, obj2):
                    self.matches.add((l1_idx, l2_idx))
1256457
def ave_list_v3(vec_list):
    """"""

    vec = Vec3(0, 0, 0)
    for v in vec_list:
        vec += v
    num_vecs = float(len(vec_list))
    vec = Vec3(vec.x / num_vecs, vec.y / num_vecs, vec.z / num_vecs)
    return vec
1164346
def sum(self, vector):
        """"""
        return self.from_list(
            [x + vector.vector[i] for i, x in self.to_list()]
        )
17259
def example():
    """"""
    J,v = multidict({1:16, 2:19, 3:23, 4:28})
    a = {(1,1):2,    (1,2):3,    (1,3):4,    (1,4):5,
         (2,1):3000, (2,2):3500, (2,3):5100, (2,4):7200,
         }
    I,b = multidict({1:7, 2:10000})
    return I,J,v,a,b
641580
def reduce(vector):
        
        if type(vector) is list: # matrix
            return array(list(map(multiply.reduce, vector)))
        else:
            return reduce(operator.mul, vector)
4242
def column_vectors(self):
        """"""
        a, b, c, d, e, f, _, _, _ = self
        return (a, d), (b, e), (c, f)
620751
def d2kvlist(d):
    '''
        
    '''
    kl = list(d.keys())
    vl = list(d.values())
    return((kl,vl))
1110273
def flatten_list(l):
    
    return list(chain.from_iterable(repeat(x,1) if isinstance(x,str) else x for x in l))
343034
def multidict_to_dict(d):
    
    return dict((k, v[0] if len(v) == 1 else v) for k, v in iterlists(d))
858508
def dictify(r, root=True):
    """"""
    if root:
        return {r.tag: dictify(r, False)}
    d = {}
    if r.text and r.text.strip():
        try:
            return int(r.text)
        except ValueError:
            try:
                return float(r.text)
            except ValueError:
                return r.text
    for x in r.findall("./*"):
        if x.tag in d and not isinstance(d[x.tag], list):
            d[x.tag] = [d[x.tag]]
            d[x.tag].append(dictify(x, False))
        else:
            d[x.tag] = dictify(x, False)
    return d
876605
def toList(variable, types=(basestring, int, float, )):
    
    if isinstance(variable, types):
        return [variable]
    else:
        return variable
364562
def combined_dict(*dicts):
  """"""
  return {k: v for d in dicts for k, v in d.items()}
834830
def _construct_axes_dict_from(self, axes, **kwargs):
        """"""
        d = {a: ax for a, ax in zip(self._AXIS_ORDERS, axes)}
        d.update(kwargs)
        return d