Download the ipynb
file numpy-II.ipynb.
Create a checkerboard 10\times 10 matrix using the numpy.tile
function.
Create a 2D array with 5
s on the border and -1
s inside.
Given a 1D array, square all elements that are between 3 and 8, in place.
Given two NumPy arrays, find the smallest common element between them.
Create a random matrix of size (3, 4) and then make the principal diagonal [6101, 6102, 6103].
Create a tensor of shape (3, 4, 5) containing uniformly randomly generated integers between 13 and 33.
Create a tensor of shape (2, 5, 3) containing normally distributed numbers (round to 2 decimal places) with mean 50 and variance 9.
Create a 5\times5 symmetric matrix containing normally distributed numbers with mean 50 and variance 2.
Create a 5\times5 skew-symmetric matrix containing normally distributed numbers (outside the diagonal) with mean 0 and variance 2.
Create a 6\times6 matrix containing uniformly distributed numbers supported on [-5, 5]. Count the number of elements that are outside the range [-3, 3].
Create random vector of length 15 and replace its minimum value with -3.
Given a vector A, denoting positions of points on the real line, construct the matrix D of the mutual distance of the points, i.e., D_{ij} = |x_i - x_j| for all i,j.
Hint: Use np.outer.
Compute the Z-score of each row of a matrix.
BMI Study
For our BMI study, we will generate fabricated data using numpy.random
. As we discussed before, our features are weight
, height
, and age
.
A good model for weight
is uniform distribution supported on [105, 230]
lbs. Similarly, age
and height
can be assumed to be uniformly distributed over [15, 85]
and [60, 75]
, respectively. Recall that taking measurements of 25 respondents everyday for a year makes the shape of our data tensor (365, 25, 3)
.
Since it’s good practice to use your own random random generator with a chosen seed, we will always initialize a generator and then call it to generate random numbers.
Write code to generate data for our BMI study.