You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Don't return array-types for 1x1 statistics? #2308
By default, these statistics are returned as arrays with dimension ()
>>> div = ts.diversity()
>>> div.shape
()
This is annoying because you have to do something like div[()] to access the value (not div[0], which is a tiny bit more intuitive at least). I think it would be better to just return the scalar value itself in this situation.
Hah, I was just having to look up how to un-array-ify this exact thing (since you can't json.dump( ) a numpy array and things like list(ts.diversity()) doesn't work for 0-d array). I won't be surprised if there's some good reason not to change this behavior, but if changing np.array(1.5) to 1.5 won't cause problems then I'm for it.
Activity
[-]Don't return array-types for 1x1 statistics[/-][+]Don't return array-types for 1x1 statistics?[/+]petrelharp commentedon May 29, 2022
Hah, I was just having to look up how to un-array-ify this exact thing (since you can't
json.dump( )a numpy array and things likelist(ts.diversity())doesn't work for 0-d array). I won't be surprised if there's some good reason not to change this behavior, but if changingnp.array(1.5)to1.5won't cause problems then I'm for it.jeromekelleher commentedon May 30, 2022
Looking into the documentation for numpy scalars there's no obvious reason to me why we couldn't do this.
I guess a first pass would be to try it out and see how much of our test suite it breaks?
gtsambos commentedon May 31, 2022
Cool! Happy to do this, but it will have to wait until after June.