Linear Algebra (
scipy.linalg
)
When
SciPy
is
built
using
the
optimized
ATLAS
LAPACK
and
BLAS
libraries,
it
has
very
fast
linear
algebra
capabilities.
If
you
dig
deep
enough,
all
of the raw lapack and blas libraries are available for your use for even
more speed. In this section, some easier-to-use interfaces to these
routines are described.
All
of
these
linear
algebra
routines
expect
an
object
that
can
be
converted
into a 2-dimensional array. The output of these routines is also a
two-dimensional array.
scipy.linalg vs numpy.linalg
scipy.linalg
contains
all
the
functions
in
numpy.linalg.
plus
some
other
more advanced ones not contained in numpy.linalg
Another advantage of using scipy.linalg over numpy.linalg is that it is
always
compiled
with
BLAS/LAPACK
support,
while
for
numpy
this
is
optional.
Therefore, the scipy version might be faster depending on how numpy was
installed.
Therefore, un
less you don’t want to add scipy as a dependency to your
numpy program, use scipy.linalg instead of numpy.linalg
numpy.matrix vs 2D numpy.ndarray
The
classes
that
represent
matrices,
and
basic
operations
such
as
matrix
multiplications and transpose are a part of numpy. For convenience, we
summarize the differences between numpy.matrix and numpy.ndarray here.
numpy.matrix is matrix class that has a more convenient interface than
numpy.ndarray for matrix operations. This class supports for example
MATLAB-like
creation
syntax
via
the,
has
matrix
multiplication
as
default
for the * operator, and contains I and T members that serve as shortcuts
for inverse and transpose:
>>> import numpy as np
>>> A = np.mat('[1 2;3 4]')
>>> A
matrix([[1, 2],
[3, 4]])