Data Science Academy — NumPy Exercise

Roman Ceresnak, PhD
2 min readFeb 9, 2022

--

Photo by Pixabay from Pexels

When you came to this section you had already gone through the previous lectures. I am happy that you came. I think it is time to practice what you already learned. So I prepared some tasks where you will be facing very similar tasks which we already solved in previous lessons. So let’s roll up your sleeves and have fun.

1 task:

import NumPy as numpy

2 task:

create and array of 5 zeros

output(array([ 0., 0., 0., 0., 0.]))

3 task:

create an array of 5 five

output(array([ 5., 5., 5., 5., 5.]))

4 task:

create and array of all the even integers from 10 to 30

output(array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]))

5 task:

create a 4x4 matrix

output (output (array([[0, 1, 2, 3],
[4, 5, 6, 7],
[8, 9, 10, 11],
[12,13,14,15]
])
))

6 task:

use NumPy to generate a random number between 0 and 1

output(array([0.79322785]))

7 task:

Indexing and Selection

use NumPy to generate an array of 20 random numbers sampled from a standard normal distribution

output(array([-0.05197923, 1.21748896, -0.57386538, 2.53818566, 1.2091932 , 0.13483867, 0.64465085, 2.14821592, 0.22396941, 0.43545582, -0.50247999, 1.78488665, -0.44830921, 1.16730298, -1.62576356, -0.52025096, -1.24013336, -2.1266145 , -1.72966213, 1.20374066]))

8 task:

mat = np.arange(1,26).reshape(5,5)

mat

output(array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]]))

mat(write something to get the output like bellow)

array([[12, 13, 14, 15],
[17, 18, 19, 20],
[22, 23, 24, 25]])

9 task:

mat (write something to get the output like bellow)

array([[ 2],
[ 7],
[12]])

10 task:

mat (write something to get the output like bellow)

24

I’m sure it worked great for you, even though you may have had to use Google from time to time, but that’s fine. In the work, you will use it with the help of colleagues or google every day. If you want to see the solution, I will provide it to you in the next article.

--

--

Roman Ceresnak, PhD
Roman Ceresnak, PhD

Written by Roman Ceresnak, PhD

AWS Cloud Architect. I write about education, fitness and programming. My website is pickupcloud.io

No responses yet