bug fixing in shape analysis
if the shape of arr is [3,3,3], arr(:,:,2) will return a [3,3]
array instead of [3,3,1], which means if the dimension is more
than 2, the trailing 1s should be removed.