IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Introduction to NumPy

Visualizza il corso

Istruzioni dell'esercizio

  • 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.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Create and print a 1D array of tree and stump diameters
trunk_stump_diameters = ____
print(trunk_stump_diameters)
Modifica ed esegui il codice