File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
numpy/_core/src/multiarray Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -2798,9 +2798,19 @@ PyArray_Nonzero(PyArrayObject *self)
2798
2798
{
2799
2799
int i , ndim = PyArray_NDIM (self );
2800
2800
if (ndim == 0 ) {
2801
- PyErr_SetString (PyExc_ValueError ,
2802
- "Calling nonzero on 0d arrays is not allowed. "
2803
- "Use np.atleast_1d(scalar).nonzero() instead." );
2801
+ char const * msg ;
2802
+ if (PyArray_ISBOOL (self )) {
2803
+ msg =
2804
+ "Calling nonzero on 0d arrays is not allowed. "
2805
+ "Use np.atleast_1d(scalar).nonzero() instead. "
2806
+ "If the context of this error is of the form "
2807
+ "`arr[nonzero(cond)]`, just use `arr[cond]`." ;
2808
+ } else {
2809
+ msg =
2810
+ "Calling nonzero on 0d arrays is not allowed. "
2811
+ "Use np.atleast_1d(scalar).nonzero() instead." ;
2812
+ }
2813
+ PyErr_SetString (PyExc_ValueError , msg );
2804
2814
return NULL ;
2805
2815
}
2806
2816
You can’t perform that action at this time.
0 commit comments