From 251e218bb2d780964e001d8c0eeee993f9bc9dd1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 1 Dec 2019 17:13:11 +0100 Subject: horizon: add apparent horizon equations --- utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'utils.py') diff --git a/utils.py b/utils.py index 7440919..f0ba2f4 100644 --- a/utils.py +++ b/utils.py @@ -19,6 +19,24 @@ def matrix_invert(mat): inv = np.linalg.inv(mat) return inv.transpose((1, 2, 0)).reshape(oldshape) +def matrix_det(mat): + """ + Pointwise matrix determinant. + + Given an array that stores many square matrices (e.g. the values of the + metric tensor at spacetime points), compute the array of corresponding + determinants. + + :param array_like mat: N-D array with N>2 and each mat[i0, ..., :, :] a + square matrix. + :return: Array of determinants. + """ + oldshape = mat.shape + newshape = oldshape[:2] + (np.product(mat.shape[2:]),) + + mat = mat.reshape(newshape).transpose((2, 0, 1)) + return np.linalg.det(mat).reshape(oldshape[2:]) + def array_reflect(data, parity = 1.0, axis = -1): """ Reflect an N-D array with respect to the specified axis. E.g. input -- cgit v1.2.3