Skip to content

Commit 8240f67

Browse files
committed
Allow 2D array in calc_stats and mean_cov
1 parent bdc5295 commit 8240f67

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

spectral/algorithms/algorithms.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def mean_cov(image, mask=None, index=None):
171171
172172
`image` (ndarrray, :class:`~spectral.Image`, or :class:`spectral.Iterator`):
173173
174-
If an ndarray, it should have shape `MxNxB` and the mean &
175-
covariance will be calculated for each band (third dimension).
174+
If an ndarray, it should have 2 or 3 dimensions and the mean &
175+
covariance will be calculated for the last dimension.
176176
177177
`mask` (ndarray):
178178
@@ -214,6 +214,10 @@ def mean_cov(image, mask=None, index=None):
214214
X = image.astype(np.float64)
215215
if X.ndim == 3:
216216
X = image.reshape(-1, image.shape[-1]).T
217+
elif X.ndim == 2:
218+
X = image.T
219+
else:
220+
raise ValueError('ndarray must have 2 or 3 dimensions.')
217221
if mask is not None:
218222
mask = mask.ravel()
219223
if index is not None:
@@ -813,8 +817,8 @@ def calc_stats(image, mask=None, index=None, allow_nan=False):
813817
814818
`image` (ndarrray, :class:`~spectral.Image`, or :class:`spectral.Iterator`):
815819
816-
If an ndarray, it should have shape `MxNxB` and the mean &
817-
covariance will be calculated for each band (third dimension).
820+
If an ndarray, it should have 2 or 3 dimensions and the mean &
821+
covariance will be calculated for the last dimension.
818822
819823
`mask` (ndarray):
820824

0 commit comments

Comments
 (0)