TODO 9 Using the dummy_array given below, complete the following indexing/slicing TODOs. Index/slice the first (index 0), third (index 2), and last (index 4 or -1) columns of the array dummy_array. Store the output into the variable column_slice. Hint: The output shape should be a (2, 3)! Index ONLY the first row (think about the corresponding index value) of dummy_array. Store the output into the variable row_slice. Index ONLY the second row and first two columns of dummy_array. Store the output into the variable slice_array. dummy_array = np.arange(10).reshape(2, -1) print(f"dummy_array output: \n {dummy_array}") print(f"dummy_array shape: {dummy_array.shape}")   # TODO 9.1 column_slice =  print(f"column_slice output: \n {column_slice}") print(f"column_slice shape: {column_slice.shape}") todo_check([     (column_slice.shape == (2, 3), 'column_slice did not return the correct shape of (2, 3)'),     (np.all(column_slice == np.array([[0, 2, 4], [5, 7, 9]])), 'column_slice did not return the correct values!') ]) # TODO 9.2 row_slice = print(f"row_slice output: \n {row_slice}") print(f"row_slice shape: {row_slice.shape}") todo_check([     (row_slice.shape == (5,) or row_slice.shape == (1,5), 'row_slice does not have the correct shape of (5,) or (1, 5)' ),     (np.all(row_slice == np.array([0, 1, 2, 3, 4])), 'row_slice does not contain the correct values') ]) # TODO 9.3 slice_array =  print(f"slice_array output: \n {slice_array}") print(f"slice_array shape: {slice_array.shape}") todo_check([     (slice_array.shape == (2,) or slice_array.shape == (1, 2), 'slice_array does not have the correct shape of (2,) or (1, 2)'),     (np.all(slice_array == np.array([5, 6])), 'slice_array does not contain the correct values') ])

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

TODO 9

Using the dummy_array given below, complete the following indexing/slicing TODOs.

  1. Index/slice the first (index 0), third (index 2), and last (index 4 or -1) columns of the array dummy_array. Store the output into the variable column_slice.
    1. Hint: The output shape should be a (2, 3)!
  2. Index ONLY the first row (think about the corresponding index value) of dummy_array. Store the output into the variable row_slice.
  3. Index ONLY the second row and first two columns of dummy_array. Store the output into the variable slice_array.

dummy_array = np.arange(10).reshape(2, -1)
print(f"dummy_array output: \n {dummy_array}")
print(f"dummy_array shape: {dummy_array.shape}")

 

# TODO 9.1
column_slice = 

print(f"column_slice output: \n {column_slice}")
print(f"column_slice shape: {column_slice.shape}")

todo_check([
    (column_slice.shape == (2, 3), 'column_slice did not return the correct shape of (2, 3)'),
    (np.all(column_slice == np.array([[0, 2, 4], [5, 7, 9]])), 'column_slice did not return the correct values!')
])

# TODO 9.2
row_slice =

print(f"row_slice output: \n {row_slice}")
print(f"row_slice shape: {row_slice.shape}")

todo_check([
    (row_slice.shape == (5,) or row_slice.shape == (1,5), 'row_slice does not have the correct shape of (5,) or (1, 5)' ),
    (np.all(row_slice == np.array([0, 1, 2, 3, 4])), 'row_slice does not contain the correct values')
])

# TODO 9.3
slice_array = 

print(f"slice_array output: \n {slice_array}")
print(f"slice_array shape: {slice_array.shape}")

todo_check([
    (slice_array.shape == (2,) or slice_array.shape == (1, 2), 'slice_array does not have the correct shape of (2,) or (1, 2)'),
    (np.all(slice_array == np.array([5, 6])), 'slice_array does not contain the correct values')
])

Expert Solution
Step 1

Please refer to the following steps for the complete solution to the problem above.

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Quicksort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education