def tetrahedral_barycentric_coordinates(tetra, pt):
<EOL>tetra = np.asarray(tetra)<EOL>if tetra.shape[<NUM_LIT:0>] != <NUM_LIT:4>:<EOL><INDENT>if tetra.shape[<NUM_LIT:1>] == <NUM_LIT:4>:<EOL><INDENT>if tetra.shape[<NUM_LIT:0>] == <NUM_LIT:3>:<EOL><INDENT>tetra = np.transpose(tetra, (<NUM_LIT:1>,<NUM_LIT:0>) if len(tetra.shape) == <NUM_LIT:2> else (<NUM_LIT:1>,<NUM_LIT:0>,<NUM_LIT:2>))<EOL><DEDENT>else:<EOL><INDENT>tetra = np.transpose(tetra, (<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:0>))<EOL><DEDENT><DEDENT>elif tetra.shape[<NUM_LIT:1>] == <NUM_LIT:3>:<EOL><INDENT>tetra = np.transpose(tetra, (<NUM_LIT:2>,<NUM_LIT:1>,<NUM_LIT:0>))<EOL><DEDENT>else:<EOL><INDENT>tetra = np.transpose(tetra, (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:1>))<EOL><DEDENT><DEDENT>elif tetra.shape[<NUM_LIT:1>] != <NUM_LIT:3>:<EOL><INDENT>tetra = np.transpose(tetra, (<NUM_LIT:0>,<NUM_LIT:2>,<NUM_LIT:1>))<EOL><DEDENT>if pt.shape[<NUM_LIT:0>] != <NUM_LIT:3>: pt = pt.T<EOL>d_ = det_4x3(tetra[<NUM_LIT:0>], tetra[<NUM_LIT:1>], tetra[<NUM_LIT:2>], tetra[<NUM_LIT:3>])<EOL>d0 = det_4x3(pt,       tetra[<NUM_LIT:1>], tetra[<NUM_LIT:2>], tetra[<NUM_LIT:3>])<EOL>d1 = det_4x3(tetra[<NUM_LIT:0>], pt,       tetra[<NUM_LIT:2>], tetra[<NUM_LIT:3>])<EOL>d2 = det_4x3(tetra[<NUM_LIT:0>], tetra[<NUM_LIT:1>], pt,       tetra[<NUM_LIT:3>])<EOL>d3 = det_4x3(tetra[<NUM_LIT:0>], tetra[<NUM_LIT:1>], tetra[<NUM_LIT:2>], pt)<EOL>s_ = np.sign(d_)<EOL>z_ = np.logical_or(np.any([s_ * si == -<NUM_LIT:1> for si in np.sign([d0,d1,d2,d3])], axis=<NUM_LIT:0>),<EOL>np.isclose(d_,<NUM_LIT:0>))<EOL>x_ = np.logical_not(z_)<EOL>d_inv = x_ / (x_ * d_ + z_)<EOL>return np.asarray([d_inv * dq for dq in (d0,d1,d2,d3)])<EOL>
tetrahedral_barycentric_coordinates(tetrahedron, point) yields a list of weights for each vertex
  in the given tetrahedron in the same order as the vertices given. If all weights are 0, then
  the point is not inside the tetrahedron.