We have seen that it is possible to do linear algebra in NumPy with matrices described by 2-dimensional arrays. In this

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

We have seen that it is possible to do linear algebra in NumPy with matrices described by 2-dimensional arrays. In this

Post by answerhappygod »

We Have Seen That It Is Possible To Do Linear Algebra In Numpy With Matrices Described By 2 Dimensional Arrays In This 1
We Have Seen That It Is Possible To Do Linear Algebra In Numpy With Matrices Described By 2 Dimensional Arrays In This 1 (97.75 KiB) Viewed 27 times
def find_max_column_value(A,i,j):
# YOUR CODE HERE
raise NotImplementedError()
# Tests that the algorithm finds the correct value
# Marks: 5
from nose.tools import assert_equal
import numpy as np
A = np.array([[ 9, 6, 7, 8, 1, 7,
2], [ 8, 2, 6, 5, 1, 5,
3], [ 7, 3, 1, 4, 5, 10,
1],
[10, 5,
7, 5, 4, 6, 2], [ 5, 5,
2, 6, 4, 2, 7]])
assert_equal(find_max_column_value(A,0,0),(10,3))
# Tests that the algorithm finds the correct value
# Marks: 5
from nose.tools import assert_equal
import numpy as np
A = np.array([[ 9, 6, 7, 8, 1, 7,
2], [ 8, 2, 6, 5, 1, 5,
3], [ 7, 3, 1, 4, 5, 10,
1],
[10, 5,
7, 5, 4, 6, 2], [ 5, 5,
2, 6, 4, 2, 7]])
assert_equal(find_max_column_value(A,2,4),(5,2))
# Tests that the algorithm raises IndexError
# Marks: 5
from nose.tools import assert_raises
import numpy as np
A = np.array([[ 9, 6, 7, 8, 1, 7,
2], [ 8, 2, 6, 5, 1, 5,
3], [ 7, 3, 1, 4, 5, 10,
1],
[10, 5,
7, 5, 4, 6, 2], [ 5, 5,
2, 6, 4, 2, 7]])
assert_raises(IndexError,find_max_column_value,A,-1,0)
# Tests that the algorithm raises IndexError
# Marks: 5
from nose.tools import assert_raises
import numpy as np
A = np.array([[ 9, 6, 7, 8, 1, 7,
2], [ 8, 2, 6, 5, 1, 5,
3], [ 7, 3, 1, 4, 5, 10,
1],
[10, 5,
7, 5, 4, 6, 2], [ 5, 5,
2, 6, 4, 2, 7]])
assert_raises(IndexError,find_max_column_value,A,10,0)
# Tests that algorithm finds the correct value for another
matrix
# Marks: 5
from nose.tools import assert_equal
import numpy as np\
# Tests that the algorithm finds the correct value for another
matrix
# Marks: 5
from nose.tools import assert_equal
import numpy as np
We have seen that it is possible to do linear algebra in NumPy with matrices described by 2-dimensional arrays. In this question we will write a function to perform Gaussian Elimination in Python using NumPy. (a) [30 Marks] Write a function that takes as input a Matrix A (given as a 2-dimensional NumPy-array) and two integers i and j and returns the entry in column j with maximum absolute value amongst rows i, i + 1,.. together with its row index (counted in the entire matrix). In other words, if A is an rx k matrix, A = (amn) where 0 <m <r-1 and 0 <n<k – 1, then the function should return max{\amil : i sm<r}, together with the value of m for which this maximum occurs. Note that indexing for rows and columns are counted from 0 as usual. The function should raise a ValueError if the input i is not the index of a column of A or if j is not the index of a row of A. def find_max_column_value (A, i, j):
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply