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

. 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:
&gt; &gt; &gt;r
array ([ [3, 2, 5, 8, 9],
[1, 4, 8, 5, 8 ],
[4, 5, 5, 9, 5 ],
[4, 5, 4, 4, 8 ]])
&gt;&gt;&gt; znm(r )
array ([ [0, 0, 0, 0, 9],
[0, 0, 8, 0, 0],
[0, 0, 0, 9, 0 ],
[0, 0, 0, 0, 8]])
&gt;&gt;&gt; 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.

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

acinia

r

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