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.
Questo esercizio fa parte del corso
Writing Efficient Python Code
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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)