Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code cells below perform the following tasks: Create matrices A 0 , dots, A 9 each of size 5 3 which represent the digits

The code cells below perform the following tasks:
Create matrices A0,dots,A9 each of size 53 which represent the digits 0 to 9
Visualize the matrices as 53 pixel images
Flatten each matrix Ak into a vector vk of length 15 and construct a 1510 matrix A with
vectors v0,dots,v9 in the columns:
A=[???v0cdotsv9]
Use the matrix A to answer the problems (a)-(e) below.
A0=np.array([[1.,1.,1.],
[1.,0.,1.],
[1.,0.,1.],
[1.,0.,1.],
[1.,1.,1.]])
A1=np.array([[0.,1.,0.],
[0.,1.,0.],
[0.,1.,0.],
[0.,1.,0.],
[0.,1.,0.]])
A2=np.array([[1.,1.,1.],
[0.,0.,1.],
[1.,1.,1.],
[1.,0.,0.],
[1.,1.,1.]])A3=np.array([[1.,1.,1.],
[0.,0.,1.],
[0.,1.,1.],
[0.,0.,1.],
[1.,1.,1.]])
A4=np.array([[1.,0.,1.],
[1.,0.,1.],
[1.,1.,1.],
[0.,0.,1.],
[0.,0.,1.]])
A5=np.array([1.,1.,1.],
[1.,0.,0.],
[1.,1.,1.],
[0.,0.,1.],
[1.,1.,1.]]
A6=np.array([1.,1.,1.],
[1.,0.,0.],
[1.,1.,1.],
[1.,0.,1.],
[1.,1.,1.]]
A7=np.array([[1.,1.,1.],
[0.,0.,1.],
[0.,0.,1.],
[0.,0.,1.],
[0.,0.,1.]])
A8= np.array([[1.,1.,1.], Flatten each matrix into a vector of length 15 and put the vectors into the columns of a matrix A :
A= np.column_stack([digit.flatten() for digit in digits])
A
Let vk be the k th column of A. Remember that indices start at 0 in Python. The vector vk
reshaped into a 53 matrix is exactly Ak. For example, the column at index 4 in A reshaped
into a 53 matrix is displayed below. Problem 2c (3 marks)
The digit 8 looks like a combination of 2 and 5. Compute the orthogonal projection of v8 onto
span{v2,v5}. Save the result as proj825.
Note that you can select columns 2 and 5 from matrix A and save to variable
with the
command:
A25=A[:,[2,5]]
and compute the thin QR decomposition using the function scipy. linalg. qr with the
parameter mode='economic':
Q1,R1= la.qr(A25,mode='economic')
Recall the projection of a vector v onto R(M) for some matrix M is Q1Q1Tv where
M=Q1R1.
#Y
# Test 1: Verify type and size of proj825.(1 mark)
assert isinstance(proj825,np.ndarray)
assert proj825.size ==15
print("Test 1: Success!")plt.show()
Problem 2d (2 marks)
Find the shortest distance from v9 to span{v0,v1,v2,v3,v4}. Save the result as
distance9. Use the function scipy. linalg. norm to compute the norm.
# YOUR CODE HERE
# Test 1: Verify distance9 is a positive number close to 0.7.(1 mark)
assert distance9>0
assert np.round(distance 9,1
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the preferred personality?

Answered: 1 week ago

Question

What is the relationship between humans?

Answered: 1 week ago