n_dimensions#
- paramcheckup.numpy_arrays.n_dimensions(array, param_name, ndim, kind, kind_name, stacklevel=4, error=True)[source]#
This function checks whether a numpy array has n_dimensions.
- Parameters:
- arraynumpy array
The numpy array to check the dimensions;
- param_namestr
The name of the parameter that received the variable in arrays;
- ndimint, optional
The number of dimentions that array must have;
- kindstr
The object where param_name is applied (function, method, class, etc.);
- kind_namestr
The name of the object kind;
- stacklevelint, optional
The stacking level (default is
4);- errorbool, optional
Whether to display error text (True, default) or not (False);
- Returns:
- outputTrue
If array HAS ndim;
- raisesValueError
If array DOES NOT HAVE ndim;
Examples
>>> from paramcheckup import numpy_arrays >>> import numpy as np >>> output = numpy_arrays.n_dimensions( array=np.array([1, 2, 3, 4, 5]), param_name="x_data", ndim=1, kind="function", kind_name="ttest", stacklevel=3, error=True, ) >>> print(output) True
>>> from paramcheckup import numpy_arrays >>> import numpy as np >>> output = numpy_arrays.n_dimensions( array=np.array([1, 2, 3, 4, 5]), param_name="x_data", ndim=2, kind="function", kind_name="ttest", stacklevel=3, error=False, ) UserWarning at line 3: The array `x_data` in function `ttest` must have `2` dimensions, but it has `ndim = 1'.