Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Arrays Write the following functions. See the commented out part of the program for expected results. Also, make sure your functions dont modify the array

Arrays

Write the following functions. See the commented out part of the program for expected results. Also, make sure your functions dont modify the array (if any received as parameter.

1. Write the function is_square(A) that receives an array A and determines if it is square. An array is square if it has two dimensions and they are the same size (that is, it has the same number of rows and columns).

2. The numpy function np.max(A) returns the maximum value in array A. Write the function max_loop(A) that uses a loop to find the maximum value in 1D array A.

3. The numpy function np.argmax(A) returns the index where the maximum value in array A is stored. Write the function argmax_loop(A) that uses a loop to find the argmax in 1D array A.

4. The numpy function np.sum(A) returns the sum of the elements in array A. Write the function sum_loop(A) that uses a loop to compute the sum of the elements in 1D array A.

5. Write the function sum_row(A,n) that receives a 2D array of integers A and a positive integer n and returns the sum of row n in A. You may use built-in numpy functions.

6. Write the function sum_column(A,n) that receives a 2D array of integers A and a positive integer n, and returns the sum of column n in A. You may use built-in numpy functions.

7. Write the function first_n_rows(A,n) that receives a 2D array A and an integer n, where n>0, and returns a 2D array containing the first n rows of A (or all of A if A has less than n rows).

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

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

Students also viewed these Databases questions

Question

In most cases, medication is prescribed by physicians.

Answered: 1 week ago

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago