search
HomeBackend DevelopmentPython TutorialHow to use Python to find the norm and determinant of a matrix

In the function of scipy.linalg, two parameters are often provided. One is check_finite. When it is True, a limited check will be performed. The other type is overwrite_xxxx, which indicates whether xxxx can be overwritten during the calculation process. For the sake of simplicity, it will be said later that a provides an overwrite switch, which means there is a parameter overwrite_a. When it is True, a is allowed to be overwritten during the calculation process; If a limited check switch is provided, it means that the check_finite parameter is provided.

Norm

The function norm is provided in scipy.linalg to find the norm, which is defined as

norm(a, ord=None, axis=None, keepdims=False, check_finite=True)

Whereord is used to declare the order of the norm

##ordMatrix normVector norm #None'fro' ##'nuc'-##max(sum(abs(a), axis=1))max ⁡ ( ∣ a ∣ ) -infmin(sum(abs(a), axis=1)) min ⁡ ( ∣ a ∣ ) 0-##sum(a!= 0)max(sum(abs(a), axis=0))-1min(sum(abs(a), axis=0))2-2## If ord is a non-zero integer, recorded as n nn. Let a i a_iai be the elements in matrix a aa, then the n nn norm of the matrix is ​​



Frobenius norm 2-Norm
Frobenius norm -
Nuclear norm ##inf
1


2-Norm (maximum singular value)

Minimum singular value
a
is a vector, if

nuclear norm The number is also called the "trace norm" and represents the sum of all singular values ​​of the matrix. Frobenius norm can be defined as

How to use Python to find the norm and determinant of a matrix

The essence is the natural generalization of the 2-norm of vectors in matrices.

In addition to

scipy.linalg

, How to use Python to find the norm and determinant of a matrixnorm

is also provided in

numpy.linalg

, and its parameters are

norm(x, ord=None, axis=None, keepdims=False)
The optional parameters of order are the same as the norm function in scipy.linalg

.

DeterminantIn scipy.linalg, the determinant function is det

, and its definition is very simple, except for the matrix to be found

Apart from a

, there are only override switches and limited checks of

a. The example is as follows

import numpy as np
from scipy import linalg
a = np.array([[1,2,3], [4,5,6], [7,8,9]])
linalg.det(a)
# 0.0
a = np.array([[0,2,3], [4,5,6], [7,8,9]])
linalg.det(a)
# 3.0
tracescipy.linalg

does not provide the

trace

function, but

numpy

Provided, it is defined as

umpy.trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None)
whereoffset

is the offset, indicating the offset relative to the main diagonal

  • axis1, axis2 represents the coordinate axis

  • ##dtype

    The data type used to adjust the output value

    >>> x = np.random.rand(3,3)
    >>> print(x)
    [[0.26832187 0.64615363 0.09006217]
     [0.63106319 0.65573765 0.35842304]
     [0.66629322 0.16999836 0.92357658]]
    >>> np.trace(x)
    1.8476361016546932

The above is the detailed content of How to use Python to find the norm and determinant of a matrix. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Are Python lists dynamic arrays or linked lists under the hood?Are Python lists dynamic arrays or linked lists under the hood?May 07, 2025 am 12:16 AM

Pythonlistsareimplementedasdynamicarrays,notlinkedlists.1)Theyarestoredincontiguousmemoryblocks,whichmayrequirereallocationwhenappendingitems,impactingperformance.2)Linkedlistswouldofferefficientinsertions/deletionsbutslowerindexedaccess,leadingPytho

How do you remove elements from a Python list?How do you remove elements from a Python list?May 07, 2025 am 12:15 AM

Pythonoffersfourmainmethodstoremoveelementsfromalist:1)remove(value)removesthefirstoccurrenceofavalue,2)pop(index)removesandreturnsanelementataspecifiedindex,3)delstatementremoveselementsbyindexorslice,and4)clear()removesallitemsfromthelist.Eachmetho

What should you check if you get a 'Permission denied' error when trying to run a script?What should you check if you get a 'Permission denied' error when trying to run a script?May 07, 2025 am 12:12 AM

Toresolvea"Permissiondenied"errorwhenrunningascript,followthesesteps:1)Checkandadjustthescript'spermissionsusingchmod xmyscript.shtomakeitexecutable.2)Ensurethescriptislocatedinadirectorywhereyouhavewritepermissions,suchasyourhomedirectory.

How are arrays used in image processing with Python?How are arrays used in image processing with Python?May 07, 2025 am 12:04 AM

ArraysarecrucialinPythonimageprocessingastheyenableefficientmanipulationandanalysisofimagedata.1)ImagesareconvertedtoNumPyarrays,withgrayscaleimagesas2Darraysandcolorimagesas3Darrays.2)Arraysallowforvectorizedoperations,enablingfastadjustmentslikebri

For what types of operations are arrays significantly faster than lists?For what types of operations are arrays significantly faster than lists?May 07, 2025 am 12:01 AM

Arraysaresignificantlyfasterthanlistsforoperationsbenefitingfromdirectmemoryaccessandfixed-sizestructures.1)Accessingelements:Arraysprovideconstant-timeaccessduetocontiguousmemorystorage.2)Iteration:Arraysleveragecachelocalityforfasteriteration.3)Mem

Explain the performance differences in element-wise operations between lists and arrays.Explain the performance differences in element-wise operations between lists and arrays.May 06, 2025 am 12:15 AM

Arraysarebetterforelement-wiseoperationsduetofasteraccessandoptimizedimplementations.1)Arrayshavecontiguousmemoryfordirectaccess,enhancingperformance.2)Listsareflexiblebutslowerduetopotentialdynamicresizing.3)Forlargedatasets,arrays,especiallywithlib

How can you perform mathematical operations on entire NumPy arrays efficiently?How can you perform mathematical operations on entire NumPy arrays efficiently?May 06, 2025 am 12:15 AM

Mathematical operations of the entire array in NumPy can be efficiently implemented through vectorized operations. 1) Use simple operators such as addition (arr 2) to perform operations on arrays. 2) NumPy uses the underlying C language library, which improves the computing speed. 3) You can perform complex operations such as multiplication, division, and exponents. 4) Pay attention to broadcast operations to ensure that the array shape is compatible. 5) Using NumPy functions such as np.sum() can significantly improve performance.

How do you insert elements into a Python array?How do you insert elements into a Python array?May 06, 2025 am 12:14 AM

In Python, there are two main methods for inserting elements into a list: 1) Using the insert(index, value) method, you can insert elements at the specified index, but inserting at the beginning of a large list is inefficient; 2) Using the append(value) method, add elements at the end of the list, which is highly efficient. For large lists, it is recommended to use append() or consider using deque or NumPy arrays to optimize performance.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment