You won’t be able to retain the same shape or dimensions.
nonzero will return a 2-dimensional tensor where dim1 contains the indices for each dimension or alternatively you can return these indices as a tuple.
How should the result tensor look for your use case?
E.g. assuming that not all rows in N contain a nonzero value, what should be stored at this particular index in dim0?