Solved by Expert Tutors
(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,...
Solved by Expert Tutors
Question

Please solve using Python:


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.

Step-by-step answer

The student who asked this found it Helpful

ng elit. Nam lacinia pu

, consectetur adipiscing elit. Nam lacin

acinia pulvi

ng elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae oixcefficixceultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscceulticece, dictum vitae odio. Donec a


nec facilis

aciniaCapture.PNG

Capture.PNG
r

Subscribe 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.

  • -

    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
Let our 24/7 Python Programming tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes