Python numpy.linalg.det() Examples
The following are 30
code examples of numpy.linalg.det().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy.linalg
, or try the search function
.
Example #1
Source File: test_linalg.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #2
Source File: test_linalg.py From recruit with Apache License 2.0 | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #3
Source File: test_linalg.py From recruit with Apache License 2.0 | 6 votes |
def do(self, a, b, tags): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #4
Source File: test_linalg.py From vnpy_crypto with MIT License | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #5
Source File: test_linalg.py From vnpy_crypto with MIT License | 6 votes |
def test_0_size(self): a = np.zeros((0, 0), dtype=np.complex64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.complex64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.complex64) assert_(res[1].dtype.type is np.float32) a = np.zeros((0, 0), dtype=np.float64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.float64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.float64) assert_(res[1].dtype.type is np.float64)
Example #6
Source File: test_linalg.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #7
Source File: test_linalg.py From vnpy_crypto with MIT License | 6 votes |
def do(self, a, b, tags): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #8
Source File: test_linalg.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def do(self, a, b): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #9
Source File: test_linalg.py From lambda-packs with MIT License | 6 votes |
def do(self, a, b): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #10
Source File: test_linalg.py From lambda-packs with MIT License | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #11
Source File: mixed.py From vnpy_crypto with MIT License | 6 votes |
def logL(self, a, ML=False): """ Individual contributions to the log-likelihood, tries to return REML contribution by default though this requires estimated fixed effect a to be passed as an argument. no constant with pi included a is not used if ML=true (should be a=None in signature) If ML is false, then the residuals are calculated for the given fixed effects parameters a. """ if ML: return (np.log(L.det(self.W)) - (self.r * np.dot(self.W, self.r)).sum()) / 2. else: if a is None: raise ValueError('need fixed effect a for REML contribution to log-likelihood') r = self.Y - np.dot(self.X, a) return (np.log(L.det(self.W)) - (r * np.dot(self.W, r)).sum()) / 2.
Example #12
Source File: anmly_detc.py From touvlo with MIT License | 6 votes |
def multi_gaussian(X, mu, sigma): """Estimates probability that examples belong to Multivariate Gaussian. Args: X (numpy.array): Features' dataset. mu (numpy.array): Mean of each feature/column of X. sigma (numpy.array): Covariance matrix for X. Returns: numpy.array: Probability density function for each example """ m, n = X.shape X = X - mu factor = X.dot(inv(sigma)) factor = multiply(factor, X) factor = - (1 / 2) * sum(factor, axis=1, keepdims=True) p = 1 / (power(2 * pi, n / 2) * sqrt(det(sigma))) p = p * exp(factor) return p
Example #13
Source File: test_linalg.py From Computable with MIT License | 6 votes |
def do(self, a, b): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #14
Source File: test_linalg.py From Computable with MIT License | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #15
Source File: test_linalg.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def do(self, a, b, tags): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #16
Source File: test_linalg.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_0_size(self): a = np.zeros((0, 0), dtype=np.complex64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.complex64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.complex64) assert_(res[1].dtype.type is np.float32) a = np.zeros((0, 0), dtype=np.float64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.float64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.float64) assert_(res[1].dtype.type is np.float64)
Example #17
Source File: studykde.py From bayestsa with Apache License 2.0 | 6 votes |
def __call__(self, params): print '???', params sd1 = params[0] sd2 = params[1] cor = params[2] if sd1 < 0. or sd1 > 10. or sd2 < 0. or sd2 > 10. or cor < -1. or cor > 1.: return np.inf bandwidth = maths.stats.choleskysqrt2d(sd1, sd2, cor) bandwidthdet = la.det(bandwidth) bandwidthinv = la.inv(bandwidth) diff = sample[self.__iidx] - sample[self.__jidx] temp = diff.dot(bandwidthinv.T) temp *= temp e = np.exp(np.sum(temp, axis=1)) s = np.sum(e**(-.25) - 4 * e**(-.5)) cost = self.__n / bandwidthdet + (2. / bandwidthdet) * s print '!!!', cost return cost / 10000.
Example #18
Source File: test_linalg.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def do(self, a, b, tags): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #19
Source File: test_linalg.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_0_size(self): a = np.zeros((0, 0), dtype=np.complex64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.complex64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.complex64) assert_(res[1].dtype.type is np.float32) a = np.zeros((0, 0), dtype=np.float64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.float64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.float64) assert_(res[1].dtype.type is np.float64)
Example #20
Source File: test_linalg.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #21
Source File: test_linalg.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def do(self, a, b, tags): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #22
Source File: test_linalg.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_0_size(self): a = np.zeros((0, 0), dtype=np.complex64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.complex64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.complex64) assert_(res[1].dtype.type is np.float32) a = np.zeros((0, 0), dtype=np.float64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.float64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.float64) assert_(res[1].dtype.type is np.float64)
Example #23
Source File: test_linalg.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #24
Source File: test_linalg.py From pySINDy with MIT License | 6 votes |
def do(self, a, b, tags): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #25
Source File: test_linalg.py From pySINDy with MIT License | 6 votes |
def test_0_size(self): a = np.zeros((0, 0), dtype=np.complex64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.complex64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.complex64) assert_(res[1].dtype.type is np.float32) a = np.zeros((0, 0), dtype=np.float64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.float64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.float64) assert_(res[1].dtype.type is np.float64)
Example #26
Source File: test_linalg.py From pySINDy with MIT License | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #27
Source File: test_linalg.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def do(self, a, b, tags): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)
Example #28
Source File: test_linalg.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_0_size(self): a = np.zeros((0, 0), dtype=np.complex64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.complex64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.complex64) assert_(res[1].dtype.type is np.float32) a = np.zeros((0, 0), dtype=np.float64) res = linalg.det(a) assert_equal(res, 1.) assert_(res.dtype.type is np.float64) res = linalg.slogdet(a) assert_equal(res, (1, 0)) assert_(res[0].dtype.type is np.float64) assert_(res[1].dtype.type is np.float64)
Example #29
Source File: test_linalg.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_byteorder_check(): # Byte order check should pass for native order if sys.byteorder == 'little': native = '<' else: native = '>' for dtt in (np.float32, np.float64): arr = np.eye(4, dtype=dtt) n_arr = arr.newbyteorder(native) sw_arr = arr.newbyteorder('S').byteswap() assert_equal(arr.dtype.byteorder, '=') for routine in (linalg.inv, linalg.det, linalg.pinv): # Normal call res = routine(arr) # Native but not '=' assert_array_equal(res, routine(n_arr)) # Swapped assert_array_equal(res, routine(sw_arr))
Example #30
Source File: test_linalg.py From ImageFusion with MIT License | 6 votes |
def do(self, a, b): d = linalg.det(a) (s, ld) = linalg.slogdet(a) if asarray(a).dtype.type in (single, double): ad = asarray(a).astype(double) else: ad = asarray(a).astype(cdouble) ev = linalg.eigvals(ad) assert_almost_equal(d, multiply.reduce(ev, axis=-1)) assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1)) s = np.atleast_1d(s) ld = np.atleast_1d(ld) m = (s != 0) assert_almost_equal(np.abs(s[m]), 1) assert_equal(ld[~m], -inf)