00:01
So in this problem we are given that we have to initialize randomly a 4x4 matrix with 0s and 1s.
00:12
And then we have to figure out which row has the greatest number of ones and which column has the greatest number of ones.
00:20
And then we have to print out that result.
00:23
So what basically this means is that we need to have an input which is of the kind 0 -1 -1, let's say 1 -0, 0, 0, 1, let's say 1, 0, 0.
00:34
0111 -0 -0 -1 -1 -1.
00:39
I say this is the input, random input that we have taken.
00:42
So we have to see row -wise the sum.
00:45
Let's say this is 3.
00:46
This sum row -wise is 2.
00:49
This is 2 and this is 3 again.
00:52
And if we see it's column -wise, sum this is 2, this is 3, this is 2, and this is 3.
00:59
It's not a good example, but we'll work with this.
01:02
So let's assume let's change something.
01:04
So that it's a bit more easy.
01:08
Put this as zero and put this also as zero, which means that these guys will change.
01:20
This is two.
01:21
This is two.
01:24
Okay, we run into a different problem now.
01:27
Let's put this also a zero.
01:31
So anyways, there will be a three here to two here and a zero here.
01:36
There will be a one over here.
01:39
So anyways, so the point is to figure out that this row has the highest number of ones and let's say there was a three over here.
01:48
So this this column has the highest sum and this row has a sum.
01:53
So we have to print out the index of this.
01:55
So row index would be three and column index would be one.
02:02
So this is what we have to print.
02:05
So let's see first how to initialize a randomly generated 4x4 matrix.
02:10
It has zeros and ones.
02:11
So we import random first which will be required in this case.
02:14
We initialize a say empty matrix and then you know it should be 4 by 4 so i've already taken two four loops which are nested one for row one for column so what we will be doing is that we will be taking this matrix filling it with a random row which has four elements then another random row which has four elements then another random row which is four elements like that four times so every time the r for r is going on the outer loop is going on, we are adding a row and every time the inner loop is going on, we are adding a element in that row.
02:52
So four times you add an element, we add one row, so like that.
02:57
So it has to go 4 by 4, 15 times.
02:59
So every time we go inside the element, we are taking an empty row list.
03:04
We are generating a random number between 0 and 1 using random dotrandt 01.
03:10
And then we are pending that number into the row, empty row.
03:13
So this way four times if you do, you have a row of four empty for random zeros and months that becomes one row and then we append that into the empty matrix as a row so and while we do that we also print these output because we want to show it as well so we print the number with an end of the print as a empty so if you don't have any empty thing if you say print number it automatically ends with a new line by default.
03:52
So you can actually give that end yourself.
03:56
In this case i've given that don't go to new line, just put an empty end, which means it will start printing next to each other unless i until and unless i then break it again because i want after four digits for it to go to the next line.
04:11
So i have to come out of that for loop and break it by printing an empty string with the default end, which is a new line end.
04:18
So that's the way it prints the matrix as well.
04:21
So i have randomly run this and this is the matrix that it has output and this is the matrix that is saved in the mat variable...