NumPy Assignment– 6

Linear Algebra & Advanced Operations

Basic Questions

  1. Create two 1D arrays [1, 2, 3] and [4, 5, 6]. Perform dot product using np.dot().
  2. Create two 2D arrays of shape (2, 2) and perform matrix multiplication using np.dot().
  3. Perform matrix multiplication on the same (2, 2) arrays using np.matmul() and compare results with np.dot().
  4. Generate a (3, 3) identity matrix. Multiply it with a (3, 3) random integer matrix and show that the result is unchanged.
  5. Create a (2, 2) matrix [[4,7],[2,6]]. Compute its determinant using np.linalg.det().
  6. Check if the determinant of a (3, 3) singular matrix is 0.
  7. Create a (2, 2) matrix [[1,2],[3,4]]. Find its inverse using np.linalg.inv().
  8. Verify that multiplying a matrix with its inverse returns the identity matrix.
  9. Create a (3, 3) matrix and compute its eigenvalues and eigenvectors using np.linalg.eig().
  10. For the same (3, 3) matrix, verify the eigen decomposition property A*v = λ*v for one eigenvalue/eigenvector pair.
  11. Solve the system of equations:
2x + y = 5 
x – y = 1
using np.linalg.solve().
  1. Solve the system:
3x + y + z = 1 
2x + 4y + z = 2
x + y + 5z = 3
using np.linalg.solve().
  1. Create a vector [3,4]. Compute its L2 norm using np.linalg.norm().
  2. Compute the L1 norm of the vector [1,-2,3,-4].
  3. Create a (3,3) diagonal matrix and compute its Frobenius norm.
  4. Show that the norm of [0,0,0] is 0.
  5. Create a (2, 2) matrix and compute its determinant, then square root of determinant using np.sqrt().
  6. Perform dot product of two random vectors of size 5.
  7. Multiply two (3,3) matrices using the @ operator (matrix multiplication).
  8. Find eigenvalues of a diagonal matrix and show they are the diagonal elements.

Intermediate Questions

  1. Generate two (3,3) random matrices. Perform matrix multiplication with dot() and verify dimensions.
  2. Compare np.dot(), np.matmul(), and @ operator on the same matrices to confirm equivalence.
  3. Create a (4,4) random integer matrix and compute its determinant. Interpret the sign of the determinant.
  4. Show that determinant of a triangular matrix is equal to the product of its diagonal elements.
  5. Generate a (3,3) invertible matrix and compute its inverse. Multiply the result with the original to verify identity.
  6. Try computing the inverse of a singular matrix and handle the error with try/except.
  7. Generate a (4,4) random matrix and compute its eigenvalues and eigenvectors.
  8. Verify eigen decomposition for all eigenvalues by computing A*v and comparing with λ*v.
  9. Solve a linear system Ax = b where A is a (3,3) matrix and b is a vector of length 3.
  10. Solve a system of equations with a randomly generated (5,5) matrix and (5,) vector.
  11. Compute vector norms for [1,2,3] using L1, L2, and infinity norms.
  12. Compute the Frobenius norm of a (3,3) matrix and explain its meaning.
  13. Generate a (3,3) orthogonal matrix and verify A.T @ A = I.
  14. Check condition number of a (3,3) random matrix using np.linalg.cond().
  15. Verify that inverse of transpose equals transpose of inverse for a (2,2) invertible matrix.
  16. Solve for current in a simple electric circuit modeled as V = IR using np.linalg.solve() with random values.
  17. Compute determinant of covariance matrix of a (5,5) random dataset.
  18. Use eigenvalues to compute the trace of a (3,3) matrix and compare with np.trace().
  19. Find eigenvalues of a symmetric matrix and confirm they are real numbers.
  20. Compute and compare norms of the same vector under L1, L2, and L∞ norms.

Advanced Questions

  1. Generate a (10,10) random matrix. Compute its determinant and interpret whether the matrix is invertible.
  2. Create a (6,6) random invertible matrix. Compute its inverse and multiply back to verify identity.
  3. Compute eigen decomposition of a (5,5) random symmetric matrix and verify A = VΛV⁻¹.
  4. Write a program to solve 100 random linear systems Ax=b of size (10,10) and report how many were solvable.
  5. Compute L2 norms of 1000 random vectors of size 100 and store results in an array.
  6. Build a Gram matrix by computing dot products of 5 random vectors of size 5.
  7. Simulate PCA step: generate a (5,5) covariance matrix, compute eigenvalues and eigenvectors, and project onto top 2 components.
  8. Create a (4,4) Hilbert matrix, compute its determinant, inverse, and condition number; explain numerical instability.
  9. Generate a (3,3) random matrix, compute SVD using np.linalg.svd(), and compare with eigen decomposition.
  10. Benchmark performance: compare solving Ax=b using np.linalg.inv(A) @ b vs np.linalg.solve(A,b) for large random matrices and discuss efficiency.