提取 NumPy 数组子集
子集提取操作(也就是在列表或数组后面使用方括号来取值)在列表和数组中的用法完全一样。
本练习已在后台加载 height_in 和 weight_lb 这两个列表。它们是普通列表,其中存放着 MLB 球员的身高和体重。练习还为你准备好了两个 numpy 数组:np_weight_lb 和 np_height_in。
本练习是课程的一部分
Python 入门
练习说明
- 通过打印索引为 50 的元素来从
np_weight_lb中提取子集。 - 打印
np_height_in的一个子数组,其中包含从索引 100 到 110(包含索引 110)的元素。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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