Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Two students write a = [1, 2, 3] and b = np.array([1, 2, 3]). Each of them works out a * 2, b * 2, a + a and b + b. Say what each one gives, then check by running the program. A lab has 1000 temperatures. Which of the two would you use to double all of them, and why?
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. A list repeats and joins. An array does maths place by place.
Check. a * 2 and a + a both give the longer list [1, 2, 3, 1, 2, 3]. b * 2 and b + b both give [2 4 6], the numbers doubled.
For 1000 temperatures, use an array. temps * 2 doubles all of them in one line, and fast. With a list, you would need a loop, or a list comprehension.
Answer: [1, 2, 3, 1, 2, 3] twice, then [2 4 6] twice. Use an array.
Log in to join the discussion.
Loading…