oxford_logo Dunn_School

DTC Introduction to Programming

Extension Problem for Array Structures

In Python, numpy arrays are a useful tool for performing vectorised computation. They give a MATLAB-like feel to array objects in Python. We're going to play around with them in this exercise. Thresholding is a common technique in signal processing for eliminating background noise. Check out the Python numpy randn function: it allows us to create a random vector, where each element in the vector is drawn from a standard normal distribution (mean of 0, standard deviation of 1). Import numpy by running 'import numpy as np'. Then run 'np.random.randn(1,1000)' to return a random vector of length 1000. Threshold this vector so that any value that lies outside the interval [-1,1] is set to zero. After the threshold, write something that tells you how many entries in the vector are nonzero. Think about the definition of standard deviation - is that what you expected? (Hint) (Possible Solution)