Question: In this question we explore the differences between lists and numpy arrays. First, you will create an m n matrix M filled with numbers 1

In this question we explore the differences between lists and numpy arrays.
First, you will create an mn matrix M filled with numbers 1,2,3,dots,mn in order, by
rows. For example, if m=2 and n=3, then
if m=1 and n=7, then
M=[12356]
4
M=[1,2,3,4,5,6,7]
[123457891012131415]
11
6
1
and ifm=3 and n=5
Parts (a)-(c): Use commands for lists only (no numpy arrays)
(a)[1] Write a function create_matrix (m,n) to create the mn matrix M as described above.
(b)[1] Write a function sum_columns(M) to create a list whose entry under index j is the
sum of all elements in the column j of M.
(c)[1] Write a function sum_rows (M) to create a list whose entry under index i is the sum
of all elements in the row i of M.
Parts (d)-(f): Use commands for numpy arrays only, such as np.arange, np.reshape,
.sum, etc., as well as slicing. Do not use commands for lists, such as .append.
(d)[1] Write a function np_create_matrix (m,n) to create the mn numpy array M as de-
scribed above.
(e)[1] Write a function np_sum_columns(M) to create a numpy vector (i.e., a one-dimensional
array) whose entry under index j is the sum of all elements in the column j of M.
(f)[1] Write a function np_sum_rows(M) to create a a numpy vector (i.e., a one-dimensional
array) whose entry under index i is the sum of all elements in the row i of M.
In this question we explore the differences

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!