Basic NumPy array operations

NumPy arrays are Python analogues of mathematical matrices, and so they support the arithmetic manipulation of all basic types, such as addition, subtraction, division, and multiplication.

Let's declare two NumPy arrays and store them as array1 and array2:

array1 = np.array([[10,20,30], [40, 50, 60], [70, 80, 90]])
array2 = np.array([[90, 80, 70], [60, 50, 40], [30, 20, 10]])

Now let's look at some examples of each arithmetic operation on these arrays:

  • Addition:

  • Subtraction:

  • Multiplication:

  • Division:

Let's now compare NumPy arrays with Python lists.