BUG: numpy.cov doesn't keep dimensions for matrix with exactly one column
Open
Nobody has claimed this yet.
00 - Bug
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
Describe the issue:
Expected Behavior:
np.cov(X, rowvar=False) returns array with same number of dimensions as X
Actual Behavior:
np.cov(X, rowvar=False) returns array with zero dimesions if X.shape[1] == 1
Reproduce the code example:
import numpy as np
# keep dimensions as expected
a = np.random.rand(100, 0)
assert np.cov(a, rowvar=False).ndim == a.ndim
c = np.random.rand(100, 2)
assert np.cov(c, rowvar=False).ndim == c.ndim
# doesn't keep dimensions
b = np.random.rand(100, 1)
assert np.cov(b, rowvar=False).ndim == b.ndim
Error message:
No response
NumPy/Python version information:
1.21.5 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0]
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
Start at the np.cov entry point and trace the rowvar=False path for an input whose shape is (100, 1). Reproduce the reported assertion, then add coverage for the one-column case and confirm that the result preserves the input dimensionality without regressing the zero- and two-column examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100