From the course: Python Functions for Data Science

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Arithmetic operations on NumPy arrays

Arithmetic operations on NumPy arrays - Python Tutorial

From the course: Python Functions for Data Science

Start my 1-month free trial

Arithmetic operations on NumPy arrays

- [Instructor] One of the advantages of working with numpy arrays is that arithmetic operations on numpy arrays are fast and convenient. Note that arithmetic operations on numpy arrays are performed element-wise. I'll be walking through some examples to demonstrate those operations. I'm initializing array A as a one-dimensional numpy array containing the odd integers between one and 20 inclusive. And I'm initializing array B as a one-dimensional numpy array containing the integers one to 10 inclusive. Let's say I want to add the elements of array A to the elements of array B, thereby creating a new numpy array that contains the result. To do this, I can use the addition operator. It would look like this. Now say I want to subtract the elements of array B from the elements of array A, thereby creating a new numpy array that contains the result. To do this, I can use a subtraction operator. It would look like this. Then say…

Contents