Skip to content
Advertisement

Tag: zero

How to change 12 random 0 to 1 in python Matrix

My program is suppose to change 12 zeros on random positions to 1 in python 6×6 matrix. This is my code. So my matrix is going to look like this at the beggining So I randomly chose an array and the element in chosen array. The problem is that different number of zeros is changed every time. Not 12 like

Make division by zero equal to zero

How can I ignore ZeroDivisionError and make n / 0 == 0? Answer Check if the denominator is zero before dividing. This avoids the overhead of catching the exception, which may be more efficient if you expect to be dividing by zero a lot.

Advertisement