21.12.2022 Views

python_para_desenvolvedores_2ed

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Processamento numérico 201

print 'Resolvendo um sistema linear:'

print numpy.linalg.solve(Z, numpy.array([0, 1, 2]))

# [ 0.33333333 1. -1. ]

Saída:

Criando uma matriz a partir de uma lista:

[[3 4 5]

[6 7 8]

[9 0 1]]

Transposta da matriz:

[[3 6 9]

[4 7 0]

[5 8 1]]

Inversa da matriz:

[[-0.23333333 0.13333333 0.1 ]

[-2.2 1.4 -0.2 ]

[ 2.1 -1.2 0.1 ]]

Multiplicando matrizes:

[[30 26 32]]

Resolvendo um sistema linear:

[ 0.33333333 1. -1. ]

O módulo numpy.linalg também implementa funções de decomposição de

matrizes:

from numpy import *

# Matriz 3x3

A = array([(9, 4, 2), (5, 3, 1), (2, 0, 7)])

print 'Matriz A:'

print A

# Decompondo usando QR

Q, R = linalg.qr(A)

# Resultados

print 'Matriz Q:'

print Q

print 'Matriz R:'

print R

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!