I don’t quite understand the expected output shape.
Your input tensor a has 16 values (1*4*2*2=16), so count_nonzero can return a value in [0, 16], while the expected output shape would contain more values.
Could you explain your use case a bit more?