Description
import numpy as np
Q1) [20 Marks] Random Number Generation
Using commands np.random.randint and np.random.rand, generate:
-
100 random integers in the interval −10 to 10.
-
uniform random numbers in the interval [0, 1]. Q2) [40 Marks] Operations with Vectors
-
-
[20 Marks]: Write a function which accepts integer n as input and outputs a data set of n points of form (xi, yi)ni=1 in the 2-dimensional plane (chosen at random) in the interval [−1, 1) ⇥ [−1, 1). Here (x, y) means points are in 2-dimensions, and the subscript i in (xi, yi) means it is the ith data point.
-
[10 Marks]: Given a point (xnew, ynew) find k = 5, 10, 15 nearest point in the data
-
set generated in part a). Distance between point in data set and the new point is given by p
(xi − xnew)2 + (yi − ynew)2. Can you find a better command in numpy to do this? (Hint:
Search in np.linalg).
-
[10 Marks]: Given a point (xnew, ynew) find k = 5, 10, 15 points in the data set generated in part
-
that make a positive angle with the new point. Implement this as a separate function.
Q3) Plotting [30 Marks]
-
[10 Marks] Plot the data set in blue and the k points obtained in Q2 a) and Q2 b) in red.
-
[10 Marks] Generate n = 100 random integers and plot their histogram.
Q4)[10 Marks] Generate n = 100 random points in the interval [−0.5, 0.5]. Plot the sample mean given by