# Boolean masks np, question 10 from practice set

Hey all,

My question relates to the above practice set.

Can someone please explain what .shape is doing here?

``````mask = np.count_nonzero(x, axis=1) == x.shape
``````

From what I understand, x.shape required otherwise output would be an array, counting each row for number of non zeroes, i.e. in above, row 1 would be 4 (4 nonzeroes, 1 zero), row 2 = 4, row 3 = 5, row 4 = 5, row 5 = 4. (please correct me if i am wrong here)

is x.shape returning it as boolean for the columns? why columns and not rows?

Thanks all

Hello @saturdaynightwrist

`x.shape` will give us the dimension of a NumPy array, ie, how many rows and columns do an array have.
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html
It will return a tuple and the first value is the number of rows, the second value is the number of columns.

`x.shape` is just indexing of getting the number of columns from array `x`.

From the code, you are trying to check if the number of non-zeros per row is the same as the number of columns of `x`. Therefore `mask` will be a boolean array, but `x.shape` will have the number of columns in `x`, `np.count_nonzero(x,axis=1)` is the number of columns that have no zero per row in `x`.
https://numpy.org/doc/stable/reference/generated/numpy.count_nonzero.html

Thanks for that explanation.

Actually, the second question is confusing me a little bit here:

the answer to the question is

``````mask = np.count_nonzero(x, axis=1) < x.shape
``````

But I did this:

``````mask = np.count_nonzero(x, axis=1) == x.shape

``````

And it worked. Though I’m a bit worried that I still don’t understand this part:

``````mask = np.count_nonzero(x, axis=1) < x.shape
``````

Hello @saturdaynightwrist
1. Create a 1-dimensional array named `rows_with_zeros` that contains all rows of `x` that contain at least one zero.