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

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

Expert Solution
Step 1

Algorithm:

  1. Start
  2. Import the numpy library as np
  3. Create a 2x5 dummy_array using np.arange and np.reshape functions
  4. Print the dummy_array and its shape
  5. Slice the first (column 0), third (column 2), and last (column 4) columns of dummy_array and store the result in column_slice
        To select multiple columns, use the syntax dummy_array[:, [column_indices]], where column_indices is a list of desired column indices
  6. Print column_slice and its shape
  7. Slice only the first row (row 0) of dummy_array and store the result in row_slice
       To select a single row, use the syntax dummy_array[row_index, :], where row_index is the desired row index
  8. Print row_slice and its shape
  9. Slice only the second row (row 1) and first two columns (columns 0 and 1) of dummy_array and store the result in slice_array
       To select a single row and multiple columns, use the syntax dummy_array[row_index, [column_indices]], where row_index is the desired row index and column_indices is a list of desired column indices
  10. Print slice_array and its shape
  11. Stop
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 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