0% found this document useful (0 votes)
5 views

MP2 exercise

Uploaded by

llyd mpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

MP2 exercise

Uploaded by

llyd mpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Filename: MAPA_LLOYDANTHONY_MP2

Answer the questions or complete the tasks outlined in bold below, use the specific method
described if applicable.

1. Import NumPy as np
#Write your code here
import numpy as np

2. Create an array of 20 zeros


#Write your code here
a = np.zeros(20, dtype=int)
print ("Matrix a: \n", a)

3. Create an array of 20 ones


#Write your code here
a = np.ones(20, dtype=int)
print ("Matrix a: \n", a_)

4. Create an array of 20 fives


#Write your code here
a = np.ones(20, dtype=int)*5
print ("Matrix a: \n", a_)

5. Create an array of the integers from 10 to 70


#Write your code here
a = np.arange(10, 71)
print ("Matrix a: \n", a)

6. Create an array of all the even integers from 10 to 70


#Write your code here
a = np.arange(10, 71, 2)
print ("Matrix a: \n", a)

7. Create a 3x3 matrix with values ranging from 10 to 18


#write your code here
matrix = np.arange(10, 19).reshape(3, 3)
matrix

8. Create a 4x4 identity matrix


#write your code here
matrix = np.identity(4, dtype=int)
matrix
9. Use NumPy to generate a random number between 0 and 5
#write your code here
from numpy import random
num=random.randint(1, 5)
print ("The number generated is: ", num)

10. Use NumPy to generate an array of 50 random numbers sampled from a standard normal
distribution
#write your code here
random_array = np.random.randn(50)
print (random_array)

Numpy Indexing and Selection

11. Run this Cell – This is our starting matrix


import numpy as np
matrix = np.arange(1,51).reshape(5,10)
matrix

12. Get the sum of all the values in matrix


#write your code here
matrix_sum = np.sum(matrix)
print (matrix_sum)
13. Get the standard deviation of the values in matrix
#write your code here
matrix_std = np.std(matrix)
print (matrix_std)

You might also like