TODO 11 Using the axis_array defined below complete the following TODOs. Hint: Think about which axis is being collapsed or the direction of the arrow for each axis in the above picture. Compute the average using np.average for each row. Store the output into the variable row_avg. Find the minimum value using np.min for each column. Store the output into the variable col_min. axis_array = np.vstack([np.full((1, 5), 2), np.full((1, 5), 5)]) print(f"axis_array output: \n {axis_array}") print(f"axis_array shape: {axis_array.shape}") # TODO 11.1 row_avg =  print(f"row_avg output: \n {row_avg}") print(f"row_avg shape: {row_avg.shape}") todo_check([     (row_avg.shape == (2,), 'row_avg does not have the correct shape of (2,)'),     (np.all(row_avg == np.array([2, 5])), 'row_avg does not have the correct values') ]) # TODO 11.2 col_min =  print(f"col_min output: \n {col_min}") print(f"col_min shape: {col_min.shape}") todo_check([     (col_min.shape == (5,), "col_min does not have the correct shape of (5,)"),     (np.all(col_min == np.array([2, 2, 2, 2, 2])), 'col_min does not have 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 11

Using the axis_array defined below complete the following TODOs.

Hint: Think about which axis is being collapsed or the direction of the arrow for each axis in the above picture.

  1. Compute the average using np.average for each row. Store the output into the variable row_avg.
  2. Find the minimum value using np.min for each column. Store the output into the variable col_min.

axis_array = np.vstack([np.full((1, 5), 2), np.full((1, 5), 5)])
print(f"axis_array output: \n {axis_array}")
print(f"axis_array shape: {axis_array.shape}")

# TODO 11.1
row_avg = 

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

todo_check([
    (row_avg.shape == (2,), 'row_avg does not have the correct shape of (2,)'),
    (np.all(row_avg == np.array([2, 5])), 'row_avg does not have the correct values')
])

# TODO 11.2
col_min = 

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

todo_check([
    (col_min.shape == (5,), "col_min does not have the correct shape of (5,)"),
    (np.all(col_min == np.array([2, 2, 2, 2, 2])), 'col_min does not have the correct values')
])

Expert Solution
Step 1

Introduction

In Python, the term "for each row" and "for each column" refers to the concept of looping over the elements in a 2-dimensional data structure, such as a matrix or a 2-dimensional array.

  • "For each row" means to iterate over the rows of a 2-dimensional data structure, where each iteration of the loop represents a row, and access is given to the elements in that row.

  • "For each column" means to iterate over the columns of a 2-dimensional data structure, where each iteration of the loop represents a column, and access is given to the elements in that column.

Here is an example of how you might use these terms in a for loop:

import numpy as np

# Create a 2-dimensional array
matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

# Loop over each row
for row in matrix:
    print(row)

# Loop over each column
for col in matrix.T:
    print(col)

 

OUTPUT:

[1 2 3]
[4 5 6]
[7 8 9]

[1 4 7]
[2 5 8]
[3 6 9]

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
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