Exercise

Deleting with np.delete()

What if your tree research focuses only on living trees on publicly-owned city blocks? It might be helpful to delete some unneeded data like the stump diameter column and some trees located on private blocks.

You've learned that NumPy's np.delete() function takes three arguments: the original array, the index or indices to be deleted, and the axis to delete along. If you don't know the index or indices of the array you'd like to delete, recall that when it is only passed one argument,np.where() returns an array of indices where a condition is met!

numpy is loaded as np, and the tree_census 2D array is available. The columns in order refer to a tree's ID, block number, trunk diameter, and stump diameter.

Instructions 1/2

undefined XP
    1
    2
  • Delete the stump diameter column from tree_census, and save the new 2D array as tree_census_no_stumps.
  • Using np.where(), find the indices of any trees on block 313879, a private block. Save the indices in an array called private_block_indices.