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)
| 202 | |
| 203 | |
| 204 | def _divide_by_count(a, b, out=None): |
| 205 | """ |
| 206 | Compute a/b ignoring invalid results. If `a` is an array the division |
| 207 | is done in place. If `a` is a scalar, then its type is preserved in the |
| 208 | output. If out is None, then a is used instead so that the division |
| 209 | is in place. Note that this is only called with `a` an inexact type. |
| 210 | |
| 211 | Parameters |
| 212 | ---------- |
| 213 | a : {ndarray, numpy scalar} |
| 214 | Numerator. Expected to be of inexact type but not checked. |
| 215 | b : {ndarray, numpy scalar} |
| 216 | Denominator. |
| 217 | out : ndarray, optional |
| 218 | Alternate output array in which to place the result. The default |
| 219 | is ``None``; if provided, it must have the same shape as the |
| 220 | expected output, but the type will be cast if necessary. |
| 221 | |
| 222 | Returns |
| 223 | ------- |
| 224 | ret : {ndarray, numpy scalar} |
| 225 | The return value is a/b. If `a` was an ndarray the division is done |
| 226 | in place. If `a` is a numpy scalar, the division preserves its type. |
| 227 | |
| 228 | """ |
| 229 | with np.errstate(invalid='ignore', divide='ignore'): |
| 230 | if isinstance(a, np.ndarray): |
| 231 | if out is None: |
| 232 | return np.divide(a, b, out=a, casting='unsafe') |
| 233 | else: |
| 234 | return np.divide(a, b, out=out, casting='unsafe') |
| 235 | elif out is None: |
| 236 | # Precaution against reduced object arrays |
| 237 | try: |
| 238 | return a.dtype.type(a / b) |
| 239 | except AttributeError: |
| 240 | return a / b |
| 241 | else: |
| 242 | # This is questionable, but currently a numpy scalar can |
| 243 | # be output to a zero dimensional array. |
| 244 | return np.divide(a, b, out=out, casting='unsafe') |
| 245 | |
| 246 | |
| 247 | def _nanmin_dispatcher(a, axis=None, out=None, keepdims=None, |