
![]() | Check the dimensions of a NumPy array:
#define NDIMCHECK(a, expected_ndim) \
if (a->nd != expected_ndim) { \
PyErr_Format(PyExc_ValueError, \
"%s array is %d-dimensional, expected to be %d-dimensional",\
QUOTE(a), a->nd, expected_ndim); \
return NULL; \
}
|
![]() | Application:
NDIMCHECK(xcoor, 1); TYPECHECK(xcoor, PyArray_DOUBLE);If xcoor is 2-dimensional, an exceptions is raised by NDIMCHECK: exceptions.ValueError xcoor array is 2-dimensional, but expected to be 1-dimensional |