I think, other than speed, that your is better than the primitive because of the reshape to 0 thing.
Reshape to 0 has been incredibly useful to me on multiple occasions. However, there also have been times when it has caused problems. My workaround is this:
![]()
With other dimensions it is a little more complicated (there might be a better way to do this, and there certainly is if you know which dimensions might be zero and how many there are):
usually I just use reshape to get a list of, e.g. 10 items which are all the same item (1,1,1,1,1,1,1,1,1,1), so all but first works then.







