The np_2d array stores information about multiple family members. Each row represents a different person, and the columns store family member attributes in the following order:
Age (years)
Weight (pounds)
Height (inches)
How is the weight of all family members selected from the np_2d array?
Correct Answer: B
In a 2D NumPy array, rows and columns represent different dimensions of the data. The indexing form array
[row_selection, column_selection] allows you to select entire rows, entire columns, or submatrices. The slice :
means "all indices along this dimension." Since each row corresponds to a family member (a person), selecting weights forallfamily members means selectingall rowsfor the weight column.
The problem states the columns are ordered as: Age (column 0), Weight (column 1), Height (column 2).
Therefore, the weight column has index 1. The expression np_2d[:, 1] uses : to take every row and 1 to take the second column, producing a 1D array (or a column view) containing the weight values for all people.
Option A, np_2d[:, 2], would select the height column, not weight. Option C, np_2d[2, :], selects the third row (the third person) and all columns-age, weight, and height for just that one person. Option D, np_2d[1, :], selects the second person's entire row.
This column selection technique is fundamental in data analysis because datasets are often stored as
"rows = observations, columns = features," and extracting a feature vector is a frequent operation before computing statistics or building models.