0% found this document useful (0 votes)
51 views2 pages

Angel - Assignment 2

Uploaded by

angelmanzi36
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)
51 views2 pages

Angel - Assignment 2

Uploaded by

angelmanzi36
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/ 2

Angel Manzi Gaju, 72052024

CS 459 Natural Language Processing


February 2nd, 2023
Lecturer: Dennis Owusu
__________________________________
Assignment 2

1. How do lists differ from sets in Python? (0.5 pts)


The main difference between List and a Set is that a set is a collection of unordered data and it
contains different elements, whereas a list is a collection of ordered and changeable data and it
allows duplicate members meaning it can contain the same elements in it.

2. How do lists differ from tuples in Python? (0.5 pts)


The main difference between tuples and lists is that tuples are immutable as opposed to lists
which are mutable, which means lists can be modified- You can add or remove items or reassign
them to different variables. Therefore, it is possible to change a list but not a tuple.
The contents of a tuple cannot change once they have been created in Python due to the
immutability of tuples.

3. What is the rank of a NumPy array? (0.5 pts)


The number of dimensions in an array determines its rank.

4. What is the shape of a NumPy array? (0.5 pts)


The shape of an array is the number of elements in each dimension. The shape of a numpy
array is the attribute of a numpy array that yields a tuple with the number of corresponding
elements for each index.

5. Write code which creates a 3d NumPy array with shape (2, 3, 4). The array will have 24
elements. The first element should be 1, the second 2, the third 3 and so on till the 24th
element. (2 pts)

Output

6. What is the element at (0, 2, 3) in the 3d NumPy array above? What is the element at (1, 3,
3)? (1 pt)
Element at (0, 2, 3): 12 Element at(1,3,3): The above position is out of bounds for the array.
7. Suppose you have a NumPy array from np.array([ [1, 2], [3, 4], [5, 6] ]). How will you create a
3-element array comprising the elements 1, 3, and 6 using integer indexing? (0.5 pt)

8. How do you perform matrix multiplication in NumPy? (0.5 pts)


Matrix multiplication in NumPy is performed using the dot function(.) or the ‘@’ operator.

9. What is broadcasting? Why is it useful? (2 pts)


NumPy's broadcasting feature allows operations between arrays of differing shapes by
automatically expanding the smaller array to fit the form of the larger array. It allows
element-wise actions on arrays of various shapes without the need for explicit looping.

10. Generate a plot that shows the month-by-month depreciation/appreciation of the cedi
against the US Dollar and British Pound for the year 2022. You can find the historical
exchange rates here: BOG Cedi Rates, 2022 (2 pts)

You might also like