View the step-by-step solution to:

Question

Please solve using Python:


alt="Screen Shot 2019-10-01 at 9.19.32 PM.png" />

Screen Shot 2019-10-01 at 9.19.32 PM.png

. znm: (16 points) This function takes an ndarray and returns a new array that is a copy of its argument,
but with all elements of each row set to zero, except for the first occurrence of the largest value in each row.
There is an optional second argument, named rows that is assumed to be a bool. If it is False, then the
operation is applied to columns instead of rows.
Example:
> > >r
array ([ [3, 2, 5, 8, 9],
[1, 4, 8, 5, 8 ],
[4, 5, 5, 9, 5 ],
[4, 5, 4, 4, 8 ]])
>>> znm(r )
array ([ [0, 0, 0, 0, 9],
[0, 0, 8, 0, 0],
[0, 0, 0, 9, 0 ],
[0, 0, 0, 0, 8]])
>>> znm (r , rows=False)
array ( [ [0, 0, 0, 0, 9],
[0, 0, 8, 0, 0 ],
[4, 5, 0, 9, 0 ],
[0, 0, 0, 0, 0]])
Use ndarray . copy to make a copy of the array. You might find ndarray . argmax to be useful, too.

Top Answer

View the full answer
Capture.PNG

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question