Working with multidimensional arrays

This section will give you a brief understanding of multidimensional arrays by going through different matrix operations.

In order to do matrix multiplication in NumPy, you have to use dot() instead of *. Let's see some examples:

In [66]: c = np.ones((4, 4))         c*cOut[66]: array([[ 1., 1., 1., 1.],                [ 1., 1., 1., 1.],                [ 1., 1., 1., 1.],                [ 1., 1., 1., 1.]])In [67]: c.dot(c)Out[67]: array([[ 4., 4., 4., 4.],                [ 4., 4., 4., 4.],                [ 4., 4., 4., 4.],                [ 4., 4., 4., 4.]])

The most important topic in working with multidimensional arrays is stacking, in other words how to merge two arrays. hstack is used for stacking arrays horizontally (column-wise) and vstack is used for stacking arrays vertically (row-wise). You can ...

Get Mastering Numerical Computing with NumPy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.