This topic material is based on the Python Programming for Data Science book and adapted for our purposes in the course.
Import numpy under the alias np
.
# Your answer here.
Create the following arrays:
int
.# Your answer here.
Use numpy to:
np.random.randn()
)# Your answer here.
Create an array of 20 linearly spaced numbers between 1 and 10.
# Your answer here.
Run the following code to create an array of shape 4 x 4 and then use indexing to produce the outputs shown below.
import numpy as np
a = np.arange(1, 26).reshape(5, -1)
20
# Your answer here.
array([[ 9, 10],
[14, 15],
[19, 20],
[24, 25]])
# Your answer here.
array([ 6, 7, 8, 9, 10])
# Your answer here.
array([[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]])
# Your answer here.
array([[ 8, 9],
[13, 14]])
# Your answer here.
Calculate the sum of all the numbers in a
.
# Your answer here.
Calculate the sum of each row in a
.
# Your answer here.
Extract all values of a
greater than the mean of a
(hint: use a boolean mask).
# Your answer here.
Find the location of the minimum value in the following array b
:
np.random.seed(123)
b = np.random.randn(10)
b
# Your answer here.
Find the location of the maximum value in the following 2D array c
(hint: there are many ways to do this question, but a quick search on stackoverflow.com will typically help you find the optimum solution for a problem, for example see post):
np.random.seed(123)
c = np.random.randn(3, 2)
c
# Your answer here.
!jupyter nbconvert _05-py-numpy-practice.ipynb --to html --template classic --output 05-py-numpy-practice.html