Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Make each of these arrays with one line of NumPy, and print its shape and its sum.
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. arange stops before its stop number, so for 1 to 10 the stop is 11. For "exactly 21 numbers", use linspace, which includes both ends.
Check. The sum of 1 to 10 is 55. The multiples of 5 are . The 21 numbers from 0 to 2 are symmetric around 1, so their sum is . The table has sevens, so the sum is 84. The zeros sum to 0.
Answer: shapes (10,), (21,), (21,), (3, 4), (10,), with the sums 55, 1050, 21, 84 and 0.
Log in to join the discussion.
Loading…