Starting from:
$30

$24

Lab 1 : Python Introduction

import numpy as np

Q1) [20 Marks] Random Number Generation

Using commands np.random.randint and np.random.rand, generate:

    (i) 100 random integers in the interval −10 to 10.

    (ii) uniform random numbers in the interval [0, 1]. Q2) [40 Marks] Operations with Vectors

        a) [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.
        b) [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).

    c) [10 Marks]: Given a point (xnew, ynew) find k = 5, 10, 15 points in the data set generated in part
    a) that make a positive angle with the new point. Implement this as a separate function.

Q3) Plotting [30 Marks]

    a) [10 Marks] Plot the data set in blue and the k points obtained in Q2 a) and Q2 b) in red.

    b) [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



as a function of k.

Also plot the functions f1 =

yk =
x1 + . . . + xk
(1)

k





q    q

k1 , f2 = −  k1

More products