In addition to what @astrofrog said, you should compute the product just once and do the `!= 0` test in advance.  So perhaps in the [code block here](https://github.com/luzuku/astropy/blob/Issue-%231522/astropy/table/pprint.py#L189) add a statement:
```
    nontrivial_multidims = np.prod(multidims) > 1
```
Then:
```
if multidims:
    if nontrivial_multidims:
        ...
    else:
        ...
```