Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started