From the course: Python Functions for Data Science
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Scalar operations on NumPy arrays - Python Tutorial
From the course: Python Functions for Data Science
Scalar operations on NumPy arrays
- Another advantage of working with Numpy Arrays is that scalar operations on Numpy Arrays are efficient and easy to do. Note that scalar operations on Numpy Arrays are performed element wise. I'll be walking through some examples to demonstrate these operations. I'm initializing a variable named arrayA as a one dimensional Numpy Array containing the even integers between two and 20 inclusive. Let's say I want to add three to each element of arrayA, thereby creating a new Numpy Array that contains the result. It would look like this. Now say I want to subtract four from each element of arrayA, thereby creating a new Numpy Array that contains the result. It would look like this. Then say I want to multiply each element of arrayA by five, thereby creating a new Numpy Array that contains the result. It would look like this. Next, say I want to divide each element of arrayA by two, thereby creating a new Numpy Array that contains…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Create NumPy arrays in Python5m 30s
-
Minimum and maximum values in NumPy arrays51s
-
Indices of min and max values in NumPy arrays1m 4s
-
Find shapes of NumPy arrays and reshape4m 23s
-
Select items or groups of items from NumPy arrays4m 35s
-
Arithmetic operations on NumPy arrays2m 5s
-
Scalar operations on NumPy arrays1m 33s
-
Statistical operations on NumPy arrays56s
-
Other operations on NumPy arrays2m 58s
-
-
-
-
-
-