Question

In: Computer Science

Question 1 Time and uncertainty in Python Measure how long it takes to append values to...

Question 1

Time and uncertainty in Python

Measure how long it takes to append values to a list and then convert that list to an array and compare this to how long it takes to concatenate the values to an empty array instead. You will do this comparison taking the uncertainty of each measurement into account. Write a Python script for the questions below.

As you will be working with individual times, use the perf_counter_ns function to work in nanoseconds instead of seconds.

(a) Time how long it takes to append the values. Use 10000 values.

  • Collect a data set of 100 measured values.

  • Plot this data in a histogram and fit a Gaussian distribution to it. Does the Gaussian distribution look like the best distribution for this? (That question is rhetorical, you may continue using the Gaussian).

  • Save the plot

  • Calculate the best approximation for the time taken to perform the append method and it's associated uncertainty (you will quote this later).

(b) Now perform the same steps above for the concatenate method.

(c) Now, quote the best approximation of the time taken and the associated uncertainties for each of the methods. Is it clear that one outperforms the other? Why?

Hint: To perform the concatenation, your code can look like:

array = np.concatenate((array, np.array([value])))

Solutions

Expert Solution

For this above question, here is the answer below. A):  For time perf_counter we can take this example: from time import perf_counter      n, m = map(int, input().split())    t1_start = perf_counter()      for i in range(n):      t = int(input()) # user gave input n times      if t % m == 0:          print(t)      # For Stop the stopwatch / counter  t1_stop = perf_counter()     print("Elapsed time:", t1_stop, t1_start)   print("Elapsed time during the whole program in seconds:",                                          t1_stop-t1_start)  

B) For Concatenating and Joining Strings,The simplest and most common method is to use the plus symbol (+) to add multiple strings together. Simply place a + between as many strings as you want to join together:

>>> 'a' + 'b' + 'c'
'abc'
In keeping with the math theme, you can also multiply a string to repeat it:

>>> 'do' * 2
'dodo'
Remember, strings are immutable! If you concatenate or repeat a string stored in a variable, you will have to assign the new string to another variable in order to keep it.

>>> orig_string = 'Hello'
>>> orig_string + ', world'
'Hello, world'
>>> orig_string
'Hello'
>>> full_sentence = orig_string + ', world'
>>> full_sentence
'Hello, world'
If we didn’t have immutable strings, full_sentence would instead output 'Hello, world, world'.

C) We can use this below function to achieve this target.

 array = np.concatenate((array, np.array([10000])))

Related Solutions

1. Retention time (tR) is a measure of how long a compound is retained on a...
1. Retention time (tR) is a measure of how long a compound is retained on a stationaryphase in column in column chromatography. In TLC, Rf was a measure of how long thecompound was retained on the stationary phase. What is the relationship between tR and Rf? 2. What would be the order of elution if one separated the pigments of spinach on columnchromatography? 3. What if any would you have to change in terms of the mobile phase if you...
1. Retention time (tR) is a measure of how long a compound is retained on a...
1. Retention time (tR) is a measure of how long a compound is retained on a stationaryphase in column in column chromatography. In TLC, Rf was a measure of how long thecompound was retained on the stationary phase. What is the relationship between tR and Rf? 2. What would be the order of elution if one separated the pigments of spinach on columnchromatography? 3. What if any would you have to change in terms of the mobile phase if you...
This is an interesting measure and takes time to digest. In France, for example, this is...
This is an interesting measure and takes time to digest. In France, for example, this is a very high number and taxes are high as a result. At the same time, there are many services like education, and healthcare that are paid for as part of this. We understand this concept when it comes to our cell phone, but in the US we have an immediate negative response to taxes. Imagine if you will your taxes go from 10,000 to...
QUESTION 1 How long? How much time in seconds does it take for the sled to...
QUESTION 1 How long? How much time in seconds does it take for the sled to go down part of a hill? A sled with a total mass of 671 kilograms is going down a straight part of a hill where the angle of incline is 10.6 degrees. The length of the straight part of the hill is 76.4 metres. The speed of the sled at the top of the hill is 4 meters per second. The combined forces of...
Drop an object from a certain height and measure the time it takes to reach the...
Drop an object from a certain height and measure the time it takes to reach the ground. Repeat at least 5 times and average the time data. Calculate this height by using the free fall formulas(this is the experimental height). Measure the height by using a measuring tape ( this is the Real height). Report Include a word description of your experiment. A drawing of your set up. Physics formulas used. Finish with a % error of the height. %...
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values...
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values in the dictionary. For example: dict1 = {1: {'una': 5, 'dos': 7, 'tres': 9, 'quar' : 11}, 2: {'dos':2, 'quar':4}, 3:{'una': 3, 'tres': 5}, 4:{'cin': 6}, 5:{'tres': 7 , 'cin': 8}} dict2 = {300:{'s': 300}, 400:{'s': 100, 'g': 100, 'p': 100}, 500: {'s': 50 ,'m': 400, 'p':30, 'i': 50}, 600: {'s': 40, 'i': 400}, 700: {'m': 100, 'p': 50}} def dict_sum(db): should give output...
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list...
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the cubes of the even numbers in values (i.e., the even numbers raised to the third power). For example: >>> cube_evens_lc([2, 5, 6, 4, 1]) result: [8, 216, 64] This version of the function may not use recursion. Write a function cube_evens_rec(values) that takes as input a...
Lab 1: Measurements and uncertainty estimation Introduction: The purpose of this lab is to measure a...
Lab 1: Measurements and uncertainty estimation Introduction: The purpose of this lab is to measure a quantity related to the static friction of glass. Static friction is the force required to start moving an object from rest. You will place a coin on the glass and lift one end until the coin begins to move. Your goal is to measure the angle at which the coin moves and understand what affects the precision and accuracy of your measurements. 1) Pick...
Question 1 a). i. To estimate the average time it takes to assemble a certain printer...
Question 1 a). i. To estimate the average time it takes to assemble a certain printer component, the industrial engineer at an electronics firm timed 40 technicians in the performance of this task, getting a mean of 12.73 minutes and a standard deviation of 2.06 minutes. Construct a 98% confidence interval for the true average time it takes to assemble the printer component. ii. A sample of 16 girls gave a mean mass of 35 kg and a standard deviation...
Question 1 a). i. To estimate the average time it takes to assemble a certain printer...
Question 1 a). i. To estimate the average time it takes to assemble a certain printer component, the industrial engineer at an electronics firm timed 40 technicians in the performance of this task, getting a mean of 12.73 minutes and a standard deviation of 2.06 minutes. Construct a 98% confidence interval for the true average time it takes to assemble the printer component. ii. A sample of 16 girls gave a mean mass of 35 kg and a standard dev...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT