Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Writing Efficient Python Code

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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)
Code bewerken en uitvoeren