import numpy as np
import matplotlib.pyplot as plt
xarray = np.arange(0,10,0.1)
xarray.shape
1.2. Create an array of normally distributed numbers with mean $\mu=0$ and standard deviation $\sigma=0.5$. It should have 20 rows and as many columns as there are elements in xarray
. Call it normal_array
:
normal_array = np.random.normal(0,0.5,(20, xarray.shape[0]))
normal_array
:normal_array.dtype
xarray
as x-variable, create a new array yarray
as y-variable using the function $y = 10* cos(x) * e^{-0.1x}$:yarray = 5*np.cos(xarray)*np.exp(-0.1*xarray)
array_abs
by taking the absolute value of array_mul
:array_abs = np.abs(yarray)
array_abs
are True
and the others False
array_bool = array_abs > 0.3
array_abs
. Check that the dimensions are the ones you expected. Also are the values around the value you expect?array_min = normal_array.std(axis = 1)
array_min.shape
array_min
yarray
vs xarray
:plt.plot(xarray, yarray,'ro')
plt.plot(xarray, yarray, '-sr')
normal_array
as an imagage and change the colormap to 'gray':plt.imshow(normal_array, cmap = 'gray')
fig, ax = plt.subplots(1,2)
ax[0].plot(xarray, yarray, '-sr')
ax[1].imshow(normal_array, cmap = 'gray')
xarray
and yarray
.xarray2 = xarray[::2]
yarray2 = yarray[::2]
plt.plot(xarray, yarray)
plt.plot(xarray2, yarray2,'o')
yarray
that are larger than 0. Plot those on top of the regular xarray
and yarray
plot.plt.plot(xarray, yarray)
plt.plot(xarray[yarray>0], yarray[yarray>0],'o')
xarray
use it to plot yarray
:flipped_array = np.flipud(xarray)
plt.plot(flipped_array, yarray)
normal_array
. Concatenate it to normal_array
along the first dimensions and plot the result:ones_array = np.ones(normal_array.shape)
concatenated = np.concatenate([ones_array, normal_array])
plt.imshow(concatenated);
yarray
represents a signal. Each line of normal_array
represents a possible random noise for that signal. Using broadcasting, try to create an array of noisy versions of yarray
using normal_array
. Finally, plot it:The last dimensions of both arrays are matching. We can therefore simply added the two arrays, and yarray
will simply be "replicated" as many times as needed:
yarray_noise = yarray + normal_array
plt.imshow(yarray_noise)