开始使用免费开始使用

NumPy 数组子集化

子集化(在列表或数组上使用方括号表示法)在列表和数组中完全相同。

本练习已在后台为您加载了两个列表 height_inweight_lb。它们以常规列表的形式包含 MLB 球员的身高和体重。同时还为您准备了两个 numpy 数组列表 np_weight_lbnp_height_in

本练习是课程的一部分

Python 入门

查看课程

练习说明

  • 通过打印索引为 50 的元素来对子集化 np_weight_lb
  • 打印 np_height_in 的一个子数组,其中包含从索引 100 到(并包含)索引 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
编辑并运行代码