Function Repository Resource:

# NumPyDet

Compute the determinant of an array in Python using the NumPy linear algebra package

Contributed by: Wolfram Staff
 ResourceFunction["NumPyDet"][array] computes the determinant of array in Python using the package NumPy. ResourceFunction["NumPyDet"][array,session] uses the specified running ExternalSessionObject session.

## Details and Options

ResourceFunction["NumPyDet"] is a wrapper function that calls the Python function numpy.linalg.det().
array must be a numeric square matrix or a tensor object representing a list of numeric square matrices.
ResourceFunction["NumPyDet"] accepts array in the form of a NumericArray object or an expression that can be converted to NumericArray.
ResourceFunction["NumPyDet"][array,session] avoids the overhead of opening a new Python session for every successive call.

## Examples

### Basic Examples (2)

Compute the determinant of a matrix in NumPy:

 In[1]:=
 In[2]:=
 Out[2]=

Or using the built-in Wolfram Language function:

 In[3]:=
 Out[3]=

### Scope (6)

Compute the determinant of a real-valued matrix:

 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

Sparse array:

 In[6]:=
 Out[6]=

NumericArray object:

 In[7]:=
 Out[7]=

Complex-valued array:

 In[8]:=
 Out[8]=

A tensor representing a list of matrices:

 In[9]:=
 Out[9]=
 In[10]:=
 Out[10]=
 In[11]:=
 Out[11]=

Compare with the built-in Det:

 In[12]:=
 Out[12]=

Make several calls to NumPyDet in the same external session:

 In[13]:=
 Out[13]=
 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=

End the session:

 In[16]:=

### Properties and Relations (3)

For relatively large matrices, the determinant cannot be computed using machine arithmetic:

 In[17]:=
 In[18]:=
 Out[18]=

Use the resource function NumPySignLogDet instead:

 In[19]:=
 Out[20]=
 In[21]:=
 Out[21]=

Or the built-in Det:

 In[22]:=
 Out[22]=

### Possible Issues (3)

Automatic conversion of the input array to a NumericArray object can fail:

 In[23]:=
 Out[23]=
 In[24]:=
 Out[24]=

Convert the array to a NumericArray before passing it to NumPyDet:

 In[25]:=
 Out[25]=

A call to NumPyDet on an arbitrary precision array fails:

 In[26]:=
 Out[26]=
 In[27]:=
 Out[27]=

Convert the array to a NumericArray before passing it to NumPyDet:

 In[28]:=
 Out[28]=

Or use the machine-precision array:

 In[29]:=
 Out[29]=

NumPyDet does not issue a warning when precision is lost:

 In[30]:=
 In[31]:=
 Out[31]=

Compare with the built-in Det computed with machine precision:

 In[32]:=
 Out[32]=

Obtain a more accurate result by computing the determinant with a higher precision using the built-in Det:

 In[33]:=
 Out[33]=

Verify the result by using still higher precision:

 In[34]:=
 Out[34]=

## Version History

• 1.0.0 – 07 December 2020