MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Writing Efficient Python Code

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode