ENH: for one variable data, np.cov should return either a scalar or a (1, 1) array, not a ndim 0 array.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
As it stands,
>>> np.cov([[1, 2, 3]])
array(1.)
I feel that this is a bit unnatural, considering that any input array of first dimension > 1 will return an ndim 2 array.
For example,
>>> np.cov([[1, 2, 3], [4, 5, 6]])
array([[1., 1.],
[1., 1.]])
I suggest that either:
- A scalar is returned. This would be useful for those people that prefer to use a single function for everything, and thus use cov for computing variance as well.
- A (1, 1) array is returned. This would provide greater consistency with what is returned. Of these two, I prefer this one. I mean, np.dot doesn't squeeze, so why should cov?
While ndim 0 arrays can be used as scalars, it feels weird.
For the lazy, https://docs.scipy.org/doc/numpy/reference/generated/numpy.cov.html
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two np.cov examples from the issue and read the linked np.cov documentation to confirm the current shape behavior. The issue leaves scalar versus (1, 1) unresolved; first get a decision on the API contract, then add coverage for the chosen one-variable result while preserving existing multi-variable behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100