#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct  8 14:33:39 2024

@author: sam
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy import sparse as sp



'''a)'''

A = (np.random.randn(20,20)-0.5)**5 # 20x20 matrix A of random normally distributed numbers centered at 0 raised to the power of 5

A[abs(A)<0.1] = 0 # sets all entries with absolute value less than 0.1 to 0, to make the matrix sparse

A2 = sp.csr_matrix(A) # converts matrix A to csr matrix form

plt.spy(A2) # visualises the matrix



'''b)'''

B = (np.random.randn(5000,5000)-0.5)**5 # 5000x5000 matrix A of random normally distributed numbers centered at 0 raised to the power of 5

B[abs(B)<0.1] = 0 # sets all entries with absolute value less than 0.1 to 0, to make the matrix sparse

B2 = sp.csr_matrix(B) # converts matrix A to csr matrix form

print(A.nbytes) # prints the size of dense matrix A
print(A2.size) # prints the size of A in csr matrix form
print(B.nbytes) # prints the size of dense matrix B
print(B2.size) # prints the size of B in csr matrix form