Question: If your 2 D numpy array has a regular structure, i . e . each row and column has a fixed number of values, complicated
If your D numpy array has a regular structure, ie each row and column has a fixed number of values, complicated ways of subsetting become very easy. Have a look at the code below where the elements a and c are extracted from a list of lists.
# regular list of lists
x abcd
x x
# numpy
import numpy as np
npx nparrayx
npx:
For regular Python lists, this is a real pain. For D numpy arrays, however, it's pretty intuitive! The indexes before the comma refer to the rows, while those after the comma refer to the columns. The : is for slicing; in this example, it tells Python to include all rows.
The code that converts the preloaded baseball list to a D numpy array is already in the script. The first column contains the players' height in inches and the second column holds player weight, in pounds. Add some lines to make the correct selections. Remember that in Python, the first element is at index baseball is available as a regular list of lists.
Instructions
XP
Print out the th row of npbaseball.
Make a new variable, npweightlb containing the entire second column of npbaseball.
Select the height first column of the th baseball player in npbaseball and print it out.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
