Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

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]]) a) Use vertical stacking to create the 4-by-2 array named array3 with array1 stacked on top of array2. b) Use horizontal stacking to create the 2-by-4 array named array4 with array2 to the right of array1. c) Use vertical stacking with two copies of array4 to create a 4-by-4 array5. d) Use horizontal stacking with two copies of array3 to create a 4-by-4 array6. Question #3 (Shallow vs. Deep Copy) In this lecture, we discussed shallow vs. deep copies of arrays. Pythons built-in list and dictionary types have copy methods that perform shallow copies. Using the following dictionary dictionary = {'Sophia': [97, 88]} demonstrate that a dictionarys 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 modules 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: a) Create a Series from the list [7, 11, 13, 17]. 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 b) Create a Series with five elements that are all 100.0. c) Create a Series with 20 elements that are all random numbers in the range 0 to 100. Use method describe to produce the Series basic descriptive statistics. d) Create a Series called temperatures of the floating-point values 98.6, 98.9, 100.2 and 97.9. Using the index keyword argument, specify the custom indices 'Julie', 'Charlie', 'Sam' and 'Andrea'. e) Form a dictionary from the names and values in Part (d), then use it to initialize a Series. Question # 6 (Pandas: DataFrames) Perform the following tasks with pandas DataFrames: a) Create a DataFrame named temperatures from a dictionary of three temperature readings each for 'Maxine', 'James' and 'Amanda'. b) Recreate the DataFrame temperatures in Part (a) with custom indices using the index keyword argument and a list containing 'Morning', 'Afternoon' and 'Evening'. c) Select from temperatures the column of temperature readings for 'Maxine'. d) Select from temperatures the row of 'Morning' temperature readings. e) Select from temperatures the rows for 'Morning' and 'Evening' temperature readings. f) Select from temperatures the columns of temperature readings for 'Amanda' and 'Maxine'. g) Select from temperatures the elements for 'Amanda' and 'Maxine' in the 'Morning' and 'Afternoon'. h) Use the describe method to produce temperatures descriptive statistics. i) Transpose temperatures. j) Sort temperatures so that its column names are in alphabetical order.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Students explore these related Programming questions