1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to NumPy

Exercise

Fancy indexing vs. np.where()

You and your tree research team are double-checking collection data by visiting a few trees in person to confirm their measurements. You've been assigned to check the data for trees on block 313879, and you'd like to make a small array of just the tree data that relates to your work.

numpy is loaded as np, and the tree_census array is available. As a reminder, the tree_census columns in order refer to a tree's ID, its block ID, its trunk diameter, and its stump diameter.

Instructions 1/2

undefined XP
  • 1
    • Using fancy indexing, create an array called block_313879 which only contains data for trees with a block ID of 313879.
  • 2
    • Using np.where(), create an array of row_indices for trees with a block ID of 313879.
    • Using row_indices, create block_313879, which contains data for trees on block 313879.