def det3(ar):
    """Returns the determinants of an array of 3 x 3 matrices.

    Parameters
    ----------
    ar : array_like, shape(n, 3, 3)
        A array of 3 x 3 arrays.

    Returns
    -------
    tot : ndarray, shape(n, )
        An array of determinants.

    Notes
    -----

    This is extremely faster than calling numpy.linalg.det for 3 x 3
    matrices and is adopted from:

    http://mail.scipy.org/pipermail/numpy-discussion/2008-August/036928.html

    """
    a = ar[..., 0, 0]; b = ar[..., 0, 1]; c = ar[..., 0, 2]
    d = ar[..., 1, 0]; e = ar[..., 1, 1]; f = ar[..., 1, 2]
    g = ar[..., 2, 0]; h = ar[..., 2, 1]; i = ar[..., 2, 2]

    t = a.copy(); t *= e; t *= i; tot = t
    t = b.copy(); t *= f; t *= g; tot += t
    t = c.copy(); t *= d; t *= h; tot += t
    t = g.copy(); t *= e; t *= c; tot -= t
    t = h.copy(); t *= f; t *= a; tot -= t
    t = i.copy(); t *= d; t *= b; tot -= t

    return tot