# Python Numpy.linalg.inv() - Matriz inversa

Jinku Hu 30 enero 2023

La función `Numpy.linalg.inv()` calcula el inverso de el array dada.

## La sintaxis de `numpy.linalg.inv()`

``````numpy.linalg.inverse(arr)
``````

### Parámetros

`arr` matriz de entrada

### Retorna

Devuelve el inverso de el array dada.

## Códigos de ejemplo: `numpy.linalg.inv()` Método

``````import numpy as np

arr = np.array([[1, 3], [5, 7]])

arr_inv = np.linalg.inv(arr)

print(arr_inv)
``````

``````[[-0.875  0.375]
[ 0.625 -0.125]]
``````

## Códigos de ejemplo: `numpy.linalg.inv()` Método con entrada de `matrix`

Si la entrada dada es una `matrix` numérica, entonces `inv()` también devuelve una `matrix`.

``````import numpy as np

arr = np.matrix([[1, 3], [5, 7]])

arr_inv = np.linalg.inv(arr)

print(arr_inv, type(arr_inv))
``````

``````[[-0.875  0.375]
[ 0.625 -0.125]] <class 'numpy.matrix'>
``````

## Códigos de ejemplo: `numpy.linalg.inv()` Con `matrix` Array

``````import numpy as np

arr = np.array([[[1, 3], [5, 7]], [[2, 5], [4, 6]]])

arr_inv = np.linalg.inv(arr)

print(arr_inv)
``````

``````[[[-0.875  0.375]
[ 0.625 -0.125]]

[[-0.75   0.625]
[ 0.5   -0.25 ]]]
``````

Si el array de entrada consiste en múltiples matrices, el método numpy `linalg.inv()` calcula el inverso de ellas a la vez.

Autor: Jinku Hu

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.