Homogenize the input *value* for easy and efficient normalization. *value* can be a scalar or sequence. Parameters ---------- value Data to normalize. Returns ------- result : masked array Masked array with t
(value)
| 2487 | |
| 2488 | @staticmethod |
| 2489 | def process_value(value): |
| 2490 | """ |
| 2491 | Homogenize the input *value* for easy and efficient normalization. |
| 2492 | |
| 2493 | *value* can be a scalar or sequence. |
| 2494 | |
| 2495 | Parameters |
| 2496 | ---------- |
| 2497 | value |
| 2498 | Data to normalize. |
| 2499 | |
| 2500 | Returns |
| 2501 | ------- |
| 2502 | result : masked array |
| 2503 | Masked array with the same shape as *value*. |
| 2504 | is_scalar : bool |
| 2505 | Whether *value* is a scalar. |
| 2506 | |
| 2507 | Notes |
| 2508 | ----- |
| 2509 | Float dtypes are preserved; integer types with two bytes or smaller are |
| 2510 | converted to np.float32, and larger types are converted to np.float64. |
| 2511 | Preserving float32 when possible, and using in-place operations, |
| 2512 | greatly improves speed for large arrays. |
| 2513 | """ |
| 2514 | is_scalar = not np.iterable(value) |
| 2515 | if is_scalar: |
| 2516 | value = [value] |
| 2517 | dtype = np.min_scalar_type(value) |
| 2518 | if np.issubdtype(dtype, np.integer) or dtype.type is np.bool_: |
| 2519 | # bool_/int8/int16 -> float32; int32/int64 -> float64 |
| 2520 | dtype = np.promote_types(dtype, np.float32) |
| 2521 | # ensure data passed in as an ndarray subclass are interpreted as |
| 2522 | # an ndarray. See issue #6622. |
| 2523 | mask = np.ma.getmask(value) |
| 2524 | data = np.asarray(value) |
| 2525 | result = np.ma.array(data, mask=mask, dtype=dtype, copy=True) |
| 2526 | return result, is_scalar |
| 2527 | |
| 2528 | def __call__(self, value, clip=None): |
| 2529 | # docstring inherited |