Software Quirk of the Day

Suppose you want to know the skewness of a list of numbers, and luckily enough you have Python close at hand. The skew() function in the SciPy stats library returns a single-element array instead of a floating-point number. Why, I have no idea, but at least the developers seem to know about it. Trying to get the value out by a sensible method like, say, indexing the array returns the error message “0-d arrays can’t be indexed.” To get the value itself, subtract 0:

result = scipy.stats.skew(list_of_values) - 0

Just one more way life has found to make itself interesting.

2 thoughts on “Software Quirk of the Day”

  1. Is skew() a function that would return a (d-1)-dimensional array when called on a d-dimensional one (this doesn’t really mesh with my recollection of the definition of skewness, but that could easily be wrong)? If so, maybe it’s just set up to return an array regardless of the dimension of the array it’s called on. That wouldn’t seem to explain the subtraching zero to get the value, but I’ve never had a reason to make a single element array, so I wouldn’t know if that’s normal or not.

  2. Aha! The mean(), std(), skew() and kurtosis() functions all return (d-1)-dimensional arrays when given a d-dimensional one, but skew() is the only one which returns a 0-d array instead of a plain number when called on a 1-d array. Still pretty quirky, if you ask me.

Comments are closed.