Practice with NumPy arrays
Let's practice slicing numpy arrays and using NumPy's broadcasting concept. Remember, broadcasting refers to a numpy array's ability to vectorize operations, so they are performed on all elements of an object at once.
A two-dimensional numpy array has been loaded into your session (called nums) and printed into the console for your convenience. numpy has been imported into your session as np.
This exercise is part of the course
Writing Efficient Python Code
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Print second row of nums
print(nums[____,____])
# Print all elements of nums that are greater than six
print(____[____ > ____])
# Double every element of nums
nums_dbl = ____ * ____
print(nums_dbl)
# Replace the third column of nums
nums[____,____] = ____[____,____] + ____
print(nums)