Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9. In a 2-d array (matrix), write a function that returns the diagonal elements as an array. Ask your TA to illustrate the diagonal elements

image text in transcribed

9. In a 2-d array (matrix), write a function that returns the diagonal elements as an array. Ask your TA to illustrate the diagonal elements for a rectangular array before you begin. 10. Populate a 2-d array of shape (10,15) with Os and 1s chosen randomly. To do this, import the module random first, and use randint(0.1) to generate a random bit. Use nditer instead of a loop here. 11. You can reshape arrays using the call np.reshape(a, newshape), where newshape is the tuple corresponding to the new shape desired. Generate an array of 24 increasing numbers starting from O using range(24). Reshape it to get the 3-d matrix a. What happens when the tuple newshape is incompatible with the size of a---ie, here a has size 24, but what if newshape is (5,5)? 12. The function np.where(condition, x, y) evaluates the condition. x,y are matrices of the same size. If condition is TRUE in a given position, it outputs the corresponding element of x in that position, else y. Take the matrix from Problem 10 above, and replace every occurence of O with -1 using np.where(condition, x, y) by choosing the arguments wisely

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

More Books

Students also viewed these Databases questions