mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-11 07:30:36 +08:00
Allow assert_nD to take multiple dimensions
This commit is contained in:
@@ -145,6 +145,9 @@ def safe_as_int(val, atol=1e-3):
|
||||
|
||||
def assert_nD(array, arg_name='image', ndim=2):
|
||||
array = np.asanyarray(array)
|
||||
if array.ndim != ndim:
|
||||
msg = "The parameter `%s` must be a %s-dimensional array"
|
||||
if isinstance(ndim, int):
|
||||
ndim = [ndim]
|
||||
if not array.ndim in ndim:
|
||||
msg = "The parameter `%s` must be a %s-dimensional array"
|
||||
raise ValueError(msg % (arg_name, ndim))
|
||||
raise ValueError(msg % (arg_name, '-or-'.join([str(n) for n in ndim]))
|
||||
|
||||
Reference in New Issue
Block a user