0

I am trying to calulate val but I get a type error.

This is a small part of matrix used in the calculation to show the data type it contains, original matrix is 30x30.

covM = [[ 9.81431930e-02, -6.94931008e-03, -1.28573646e-02],
       [-6.94931008e-03,  5.28292692e-02,  6.23429384e-03],
       [-7.04098766e-03,  2.64439715e-04, -8.66008123e-04]]

To find val I calculate:

val = math.sqrt((2*pi)**30*np.linalg.slogdet(covM))

But get this:

TypeError: can't multiply sequence by non-int of type 'float'

When I try using the normal determinant instead of the log it works fine:

val = math.sqrt((2*pi)**30*np.linalg.det(covM))

Why does this error occur with slogdet() but not det() and how can I make it work for the log determinant?

RishtarCode47
  • 365
  • 1
  • 4
  • 18
  • 1
    You get an error because [`slogdet`](https://numpy.org/devdocs/reference/generated/numpy.linalg.slogdet.html) returns two values, sign and det log. If you already know (or don't care about) the sign of the determinant, then you can use `np.linalg.slogdet(covM)[1]` to get only the log of its absolute value. – luciole75w Apr 13 '20 at 13:41

1 Answers1

0

Since np.linalg.slogdet() returns value two values, the sign of the determinant and the log determinant. I needed to specify the sign. So to get absolute values I did:

val = math.sqrt((2*pi)**30*np.linalg.slogdet(covM)[1])
RishtarCode47
  • 365
  • 1
  • 4
  • 18