Could you structure this docstring as a standard docstring, please, ie with a Parameters and Results section, and most of the current docstring moved into the Notes section.

The reason that I ask this is not purely "academic", but because when I read the function, I immediately wondered if X could be 2D or had to be 1D. Looking at the code, I believe that it won't work if X is 2D. In the case it has to be 1D, it should be renamed 'x', as capitalized letters are for matrices.