0

I want to create a function such that it when I enter a list as an argument, it'll take each individual item from that list, pass it through the function, and then return a list as the result.

In the end I want to display the results as a table where it displays the values of the input list and the output list so that you can see the data you entered and the results.

sigmas = [0.01,0.1,1,5,10,25,50]

def reconstruct (sigma=[]):
    
    nx = 400 
    ny = 400 
    theta = np.linspace(0.,180,nx)
    
    image = shepp_logan_phantom()
    
    sgram = radon(image, theta=theta)
    
    sgram_noisy[i] = sgram + sigma[i] * np.random.randn(nx, ny)
    
    reconstruction[i] = iradon (sgram_noisy[i], theta=theta)
    
    error[i] = np.linalg.norm(image-reconstruction[i])/np.linalg.norm(image)
    
    header = [r'$\sigma$','Error']
    
    tb = zip(sigma, error)
    
    table = print (tabulate(tb,headers=header))
    
    return table

test = reconstruct(sigmas)

How do I modify the code so it can do this?

  • 3
    What's your _question_? Note you're making this classic error: https://stackoverflow.com/q/1132941/3001761 – jonrsharpe Jun 20 '22 at 13:08

1 Answers1

0

First part of your problem is already solved by map function. It accepts an iterable and a function and calls the function on each object from the iterable.

Add a function that will print both lists in a format you want and your problem is solved.

matszwecja
  • 6,357
  • 2
  • 10
  • 17