Chapter 5. Working with Matrices and ufuncs

This chapter covers matrices and Universal functions (ufuncs). Matrices are well known in mathematics and have their representation in NumPy as well. Universal functions work on arrays, element by element, or on scalars. ufuncs expect a set of scalars as input and produce a set of scalars as output. Universal functions can typically be mapped to their mathematical counterparts such as add, subtract, divide, multiply, and so on. We will also introduce trigonometric, bitwise, and comparison universal functions.

In this chapter, we will cover the following topics:

  • Matrix creation
  • Matrix operations
  • Basic ufuncs
  • Trigonometric functions
  • Bitwise functions
  • Comparison functions

Matrices

Matrices in NumPy are subclasses of ndarray. We can create matrices using a special string format. They are, just like in mathematics, two-dimensional (see https://www.khanacademy.org/math/precalculus/precalc-matrices). Matrix multiplication is, as you would expect, different from the normal NumPy multiplication. The same is true for the power operator. We can create matrices with the mat(), matrix(), and bmat() functions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset