(Új oldal, tartalma: „previous up next =Exercises= ==Introduction== Some exercises to get used to numpy # Make…”)
A lap jelenlegi, 2020. május 13., 11:01-kori változata
Some exercises to get used to numpy
- Make a vector of length 10 with elements all zero! Then modify its 4th element to 1 (zeros)
- Make a 3-by-3 matrix with elements ranging from 0 up to 8 (reshape)
- Make a random vector of length 30 containing random number between 0 to 1! Calculate its average and standard deviation! (rand, mean, std)
- Make a random vector of the same length with elements between -3 and 2!
- Make a random unit vector in 5 dimensions! First make a random vector in 5 dimensions and then normalize it to unit length!
Generate 500000 random points in the rectangle . Count how many of the points (x,y) have the property that x2 > y. Use this to approximate the integral Like in the end of the lecture.
Estimate the integral of on the interval [ − 2,5] with the left Riemann sum!
Let's have a vector-to-scalar function f(x,y) = x2 + y2. Starting from (x0,y0) = ( − 1, − 1) we will wind the minimum of the function. A gradient step is when you subtract the from the (x,y) point. If you do this for small ε many times then the point will converge a point where you cannot increase the function value any more, i.e. the gradient is zero. This way you can find the minimum of the function (it will be (x,y) = (0,0)).
- Store each step along the way, and plot them with matplotlib!
Plot the function sin(x) and its derivative on the interval [ − π,π]. Calculate the derivative with finite difference method!