MulaiMulai sekarang secara gratis

Making NumPy arrays from lists

Recall how lists can contain anything? They can even contain other lists. In this exercise, you're going to demonstrate this feature and show how useful it is for creating our own NumPy arrays.

Seven lists are loaded into your workspace, each named after a day of the week: monday, tuesday, and so on. Each list contains the average hourly bicycle traffic across the Fremont bridge.

Latihan ini adalah bagian dari kursus

Python for MATLAB Users

Lihat Kursus

Petunjuk latihan

  • Create a list weekdays where each element is a daily list, starting on Monday.
  • Create a NumPy array traffic from the list weekdays.
  • Calculate the mean hourly traffic.
  • Plot the mean hourly traffic for weekdays.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create a list "weekdays" where each element is a daily list, starting on Monday
weekdays = [____]

# Create a NumPy array "traffic" from the list "weekdays"
traffic = ____(weekdays)

# Calculate the hourly mean traffic
hourly = np.____(traffic,axis=0)

# Plot the mean hourly traffic for weekdays
plt.____(____)
plt.show()
Edit dan Jalankan Kode