#### Overview of this book

Learning SciPy for Numerical and Scientific Computing Second Edition
Credits
www.PacktPub.com
Preface
Free Chapter
Introduction to SciPy
Working with the NumPy Array As a First Step to SciPy
SciPy for Linear Algebra
SciPy for Numerical Analysis
SciPy for Signal Processing
SciPy for Data Mining
SciPy for Computational Geometry
Interaction with Other Languages
Index

## Creating a matrix

In SciPy, a matrix structure is given to any one- or two-dimensional `ndarray`, with either the `matrix` or `mat` command. The complete syntax is as follows:

`numpy.matrix(data=object, dtype=None, copy=True)`

Creating matrices, the data may be given as `ndarray`, a string or a Python list (as the second example below), which is very convenient. When using strings, the semicolon denotes change of row and the comma, change of column:

```>>> A=numpy.matrix("1,2,3;4,5,6")
>>> A
```

The output is shown a follows s:

```matrix([[1, 2, 3],
[4, 5, 6]])
```

Let's look at another example:

```>>> A=numpy.matrix([[1,2,3],[4,5,6]])
>>> A
```

The output is shown as follows:

```matrix([[1, 2, 3],
[4, 5, 6]])
```

Another technique to create a matrix from a two-dimensional array is to enforce the matrix structure on a new object, copying the data of the former with the `asmatrix` routine.

A matrix is said to be sparse (http://en.wikipedia.org/wiki/Sparse_matrix) if most of its entries...