(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.

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]])

  1. a) Use vertical stacking to create the 4-by-2 array named array3 with array1

stacked on top of array2.

  1. b) Use horizontal stacking to create the 2-by-4 array named array4 with array2

to the right of array1.

  1. c) Use vertical stacking with two copies of array4 to create a 4-by-4 array5.
  2. 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. 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:

  1. 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

  1. b) Create a Series with five elements that are all 100.0.
  2. c) Create a Series with 20 elements that are all random numbers in the range 0 to
  3. Use method describe to produce the Series’ basic descriptive statistics.
  4. 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’.

  1. 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:

  1. a) Create a DataFrame named temperatures from a dictionary of three temperature

readings each for ‘Maxine’, ‘James’ and ‘Amanda’.

  1. b) Recreate the DataFrame temperatures in Part (a) with custom indices using

the index keyword argument and a list containing ‘Morning’, ‘Afternoon’

and ‘Evening’.

  1. c) Select from temperatures the column of temperature readings for ‘Maxine’.
  2. d) Select from temperatures the row of ‘Morning’ temperature readings.
  3. e) Select from temperatures the rows for ‘Morning’ and ‘Evening’ temperature

readings.

  1. f) Select from temperatures the columns of temperature readings for ‘Amanda’

and ‘Maxine’.

  1. g) Select from temperatures the elements for ‘Amanda’ and ‘Maxine’ in the

‘Morning’ and ‘Afternoon’.

  1. h) Use the describe method to produce temperatures’ descriptive statistics.
  2. i) Transpose temperatures.

j) Sort temperatures so that its column names are in alphabetical order

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

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.

Money-back guarantee

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 more

Zero-plagiarism guarantee

Each 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 more

Free-revision policy

Thanks 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 more

Privacy policy

Your 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 more

Fair-cooperation guarantee

By 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
error: Content is protected !!