Compute a/b ignoring invalid results. If `a` is an array the division is done in place. If `a` is a scalar, then its type is preserved in the output. If out is None, then a is used instead so that the division is in place. Note that this is only called with `a` an inexact type.
(a, b, out=None)
| 185 | |
| 186 | |
| 187 | def _divide_by_count(a, b, out=None): |
| 188 | """ |
| 189 | Compute a/b ignoring invalid results. If `a` is an array the division |
| 190 | is done in place. If `a` is a scalar, then its type is preserved in the |
| 191 | output. If out is None, then a is used instead so that the division |
| 192 | is in place. Note that this is only called with `a` an inexact type. |
| 193 | |
| 194 | Parameters |
| 195 | ---------- |
| 196 | a : {ndarray, numpy scalar} |
| 197 | Numerator. Expected to be of inexact type but not checked. |
| 198 | b : {ndarray, numpy scalar} |
| 199 | Denominator. |
| 200 | out : ndarray, optional |
| 201 | Alternate output array in which to place the result. The default |
| 202 | is ``None``; if provided, it must have the same shape as the |
| 203 | expected output, but the type will be cast if necessary. |
| 204 | |
| 205 | Returns |
| 206 | ------- |
| 207 | ret : {ndarray, numpy scalar} |
| 208 | The return value is a/b. If `a` was an ndarray the division is done |
| 209 | in place. If `a` is a numpy scalar, the division preserves its type. |
| 210 | |
| 211 | """ |
| 212 | with np.errstate(invalid='ignore', divide='ignore'): |
| 213 | if isinstance(a, np.ndarray): |
| 214 | if out is None: |
| 215 | return np.divide(a, b, out=a, casting='unsafe') |
| 216 | else: |
| 217 | return np.divide(a, b, out=out, casting='unsafe') |
| 218 | else: |
| 219 | if out is None: |
| 220 | # Precaution against reduced object arrays |
| 221 | try: |
| 222 | return a.dtype.type(a / b) |
| 223 | except AttributeError: |
| 224 | return a / b |
| 225 | else: |
| 226 | # This is questionable, but currently a numpy scalar can |
| 227 | # be output to a zero dimensional array. |
| 228 | return np.divide(a, b, out=out, casting='unsafe') |
| 229 | |
| 230 | |
| 231 | def _nanmin_dispatcher(a, axis=None, out=None, keepdims=None, |