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

MP2 Assignment

The document provides a series of tasks that involve using the NumPy library in Python to create and manipulate arrays and matrices. It includes instructions for creating arrays of zeros, ones, fives, and integers, as well as generating random numbers and performing basic statistical operations on a matrix. Each task is outlined with specific code examples for implementation.

Uploaded by

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

MP2 Assignment

The document provides a series of tasks that involve using the NumPy library in Python to create and manipulate arrays and matrices. It includes instructions for creating arrays of zeros, ones, fives, and integers, as well as generating random numbers and performing basic statistical operations on a matrix. Each task is outlined with specific code examples for implementation.

Uploaded by

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

Filename: SURNAME_FIRSTNAME_MP2

Answer the questions or complete the tasks outlined in bold


below, use the specific method described if applicable.

1. Import NumPy as np

import numpy as np

2. Create an array of 20 zeros

import numpy as np
a = np.zeros(20, dtype = int)
print("Matrix a : \n", a)

3. Create an array of 20 ones

import numpy as np

a = np.ones(20, dtype = int)

print("Matrix a : \n", a)

4. Create an array of 20 fives

import numpy as np
a = np.ones(20, dtype = int)*5
print("Matrix a : \n", a)

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

import numpy as np
a = np.arange(10,71)
print(“Matrix a : \n”, a)
6. Create an array of all the even integers from 10 to 70

import numpy as np
a = np.arange(10,71,2)
print("Matrix a : \n", a)

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

import numpy as np
mat = np.arange(10,19).reshape(3,3)
print("Matrix mat : \n", mat)

8. Create a 4x4 identity matrix

import numpy as np
mat = np.identity(4, dtype=int)
print("Matrix mat : \n", mat)
9. Use NumPy to generate a random number between 0 and 5

from numpy import random


num=random.randint(1,5)
print("The number generatedi is: ",num)

10. Use NumPy to generate an array of 50 random numbers


sampled from a standard normal distribution

import numpy as np
random_num = np.random.normal(0,1,50)
print("50 random numbers from a standard normal distribution
SND:")
print(random_num)

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()
13. Get the standard deviation of the values in matrix
#write your code here
matrix.std()

You might also like