Question: Consider the following code snippet, ( a ) Update the code as per the instructions ( see comments ( hashtags ) Note: Image of CSV

Consider the following code snippet,
(a) Update the code as per the instructions (see comments(hashtags) Note: Image of CSV files is attached
1 #
2 # Name :
3 # ID :
4 #
5 # heat.py - heat diffusion simulation
6 #
7 import numpy as np
8 import matplotlib.pyplot as plt
9
10 def calcheat(subarray):
11 result =0.1*(subarray.sum()+ subarray[1,1])
12 return result
13
14 def loadData(filename):
15 # Function to read heat source from a file
16 # File format 10 x 10(rows x cols)
17
18
19
20 return harray, curr
21
22
23 def main():
24 size = #Take the corresponding file size as user input.
25 filename = #Take the corresponding file name as a user input.
26 harray, curr = # Call the load data function
27 plotOption = # take plotting option as input if 1: plot each step in the
28 # simulation, if 2: plot the final output,
29
30 next = np.zeros((size,size))
31 for timestep in range(5):
32 for r in range(1, size-1):
33 for c in range (1, size-1):
34 next[r,c]= calcheat(curr[r-1:r+2, c-1:c+2])
35
36 np.where(harray>next, harray, next)
37
38 print("Time step: ", timestep)
39 print(next)
40 curr = next.copy()
41
42 # Add code for updated plotting as per plotting option.
43
44
45 if __name__=='__main__':
46 main()
Consider the following code snippet, ( a ) Update

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!