Get startedGet started for free

Creating arrays from conditions

Currently, the stump diameter and trunk diameter values in tree_census are in two different columns. Living trees have a stump diameter of zero while stumps have a trunk diameter of zero. If you'd like to include both living trees and stumps in certain research calculations, it might be useful to have their diameters together in just one column.

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.

This exercise is part of the course

Introduction to NumPy

View Course

Exercise instructions

  • Create and print a 1D array called trunk_stump_diameters, which replaces a tree's trunk diameter with its stump diameter if the trunk diameter is zero.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create and print a 1D array of tree and stump diameters
trunk_stump_diameters = ____
print(trunk_stump_diameters)
Edit and Run Code