Assignment 7b – Array Oriented Programming
Question #1:
(Flattening arrays with flatten vs. ravel) Create a 2-by-3 array containing the
first six powers of 2 beginning with 20. Flatten the array first with method flatten, then
with ravel. In each case, display the result then display the original array to show that it
was unmodified.
Question #2
(Horizontal and Vertical Stacking) Create the two-dimensional arrays
array1 = np.array([[0, 1], [2, 3]])
array2 = np.array([[4, 5], [6, 7]])
stacked on top of array2.
to the right of array1.
Question #3
(Shallow vs. Deep Copy) In this lecture, we discussed shallow vs. deep copies of
arrays. Python’s built-in list and dictionary types have copy methods that perform shallow
copies. Using the following dictionary
dictionary = {‘Sophia’: [97, 88]}
demonstrate that a dictionary’s copy method indeed performs a shallow copy. To do so,
call copy to make the shallow copy, modify the list stored in the original dictionary, then
display both dictionaries to see that they have the same contents.
Next, use the copy module’s deepcopy function to create a deep copy of the dictionary.
Modify the list stored in the original dictionary, then display both dictionaries to
prove that each has its own data.
Question #4
(Performance Analysis) In this chapter, we used %timeit to compare the average execution
times of generating a list of 6,000,000 random die rolls vs. generating an array of
6,000,000 random die rolls. Though we saw approximately two orders of magnitude performance
improvement with array, we generated the list and the array using two different random-
number generators and different techniques for building each collection. If you use the
same techniques we showed to generate a one-element list and a one-element array, creating
the list is slightly faster. Repeat the %timeit operations for one-element collections. Then do
it again for 10, 100, 1000, 10,000, 100,000, and 1,000,000 elements and compare the results
on your system
Please fill the below table and discuss which is better.
Number of Values | List average execution time | array average execution time |
1 | ||
10 | ||
100 | ||
1000 | ||
10,000 | ||
100,000 | ||
1,000,000 |
Question #5
(Pandas: Series) Perform the following tasks with pandas Series:
Number of values List average execution time array average execution time
1 1.56 μs ± 25.2 ns 1.89 μs ± 24.4 ns
10 11.6 μs ± 59.6 ns 1.96 μs ± 27.6 ns
100 109 μs ± 1.61 μs 3 μs ± 147 ns
1000 1.09 ms ± 8.59 μs 12.3 μs ± 419 ns
10,000 11.1 ms ± 210 μs 102 μs ± 669 ns
100,000 111 ms ± 1.77 ms 1.02 ms ± 32.9 μs
1,000,000 1.1 s ± 8.47 ms 10.1 ms ± 250 μs
Exercises 279
100.2 and 97.9. Using the index keyword argument, specify the custom indices
‘Julie’, ‘Charlie’, ‘Sam’ and ‘Andrea’.
a Series.
Question # 6
(Pandas: DataFrames) Perform the following tasks with pandas DataFrames:
readings each for ‘Maxine’, ‘James’ and ‘Amanda’.
the index keyword argument and a list containing ‘Morning’, ‘Afternoon’
and ‘Evening’.
readings.
and ‘Maxine’.
‘Morning’ and ‘Afternoon’.
j) Sort temperatures so that its column names are in alphabetical order
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more
Recent Comments