Question
Please help with Python homework! Only the lines with # need modification. Here is the box from the previous question: Thank you!! Here is the
Please help with Python homework! Only the lines with # need modification.
Here is the box from the previous question:
Thank you!!
Here is the code for question 5:
# rows size_1 = 20 # columns size_2 = 20 # fill the2D array with random numbers between 0 and 1 data_new = np.random.random((size_1, size_2))
data_new[5:14,5] = 4 #left column data_new[14,5:15] = 4 ### #bottom row data_new[5:15,14] = 4 ### #right column data_new[5,5:15] = 4 ### #top row
# check to see that it worked fig = plt.figure(figsize=(10,10)) plt.imshow(data_new) # play with different colors! plt.imshow(data_new, cmap='plasma') plt.imshow(data_new, cmap='magma') plt.colorbar()
Here is the code for question 6:
for step in range(20):
# generate a random location in the array using # integer random numbers rand_row = np.random.randint(size_1) rand_col = ###
# check to see whether this new point is inside or outside of the box if (rand_row > 5) and (rand_row 5) and (rand_col)
if .... : ### data_new[rand_row, rand_col] = 3
fig = plt.figure(figsize=(9,9)) plt.imshow(data_new) # play with different colors! # plt.imshow(data_new, cmap='plasma') # plt.imshow(data_new, cmap='magma') # plt.imshow(data_2, cmap = 'jet') plt.show() sleep(0.5) clear_output(wait=True)
75 15.0 0.0 25 50 75 10.0 12.5 15.0 17.5 Next, modify the code below to add a value of 4 to the array if, when the location in the array is chosen randomly, the location falls inside of the square you just drew. Specifically read about np.random.randint, which is used to generate random integers find two random integers in the right ranges use if to see if the chosen point is inside the square, if outside, change the value in the array to 3 if inside the square, change the value in the array to 2 . do not change the square itself. for step in range(20): # generate a random Location in the array using # integer random numbers rand_row = np.random.randint(size_1) rand_col = .... ### # check to see whether this new point is inside or outside of the box if (rand_row > 5) and (rand_row 5) and (rand_col)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started