Get startedGet started for free

Subsetting NumPy Arrays

Subsetting (using the square bracket notation on lists or arrays) works exactly the same with both lists and arrays.

This exercise already has two lists, height_in and weight_lb, loaded in the background for you. These contain the height and weight of the MLB players as regular lists. It also has two numpy array lists, np_weight_lb and np_height_in prepared for you.

This exercise is part of the course

Introduction to Python

View Course

Exercise instructions

  • Subset np_weight_lb by printing out the element at index 50.
  • Print out a sub-array of np_height_in that contains the elements at index 100 up to and including index 110.

Hands-on interactive exercise

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

import numpy as np

np_weight_lb = np.array(weight_lb)
np_height_in = np.array(height_in)

# Print out the weight at index 50


# Print out sub-array of np_height_in: index 100 up to and including index 110
Edit and Run Code