O'Reilly logo

Mastering Numerical Computing with NumPy by Mert Cuhadaroglu, Umit Mert Cakmak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Vector and matrix mathematics 

In the previous chapter, you practiced introductory operations with vectors and matrices. In this section, you will practice more advanced vector and matrix operations that are heavily used in linear algebra. Let's remember the dot product perspective on matrix manipulation and how it can be done with different methods when you have 2-D arrays. The following code block shows alternative ways of performing dot product calculation:

In [1]: import numpy as np         a = np.arange(12).reshape(3,2)         b = np.arange(15).reshape(2,5)         print(a)         print(b)Out[1]: [[ 0 1]  [ 2 3]  [ 4 5]] [[ 0 1 2 3 4]  [ 5 6 7 8 9] In [2]: np.dot(a,b)Out[2]: array([[ 5,  6,  7,  8,  9],                [15, 20, 25, 30, 35],                [25, 34, 43, 52, 61]]) In [3]: np.matmul(a,b) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required