Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started