Convert the input to a masked array, conserving subclasses. If `a` is a subclass of `MaskedArray`, its class is conserved. No copy is performed if the input is already an `ndarray`. Parameters ---------- a : array_like Input data, in any form that can be converted
(a, dtype=None, order=None)
| 8674 | |
| 8675 | |
| 8676 | def asanyarray(a, dtype=None, order=None): |
| 8677 | """ |
| 8678 | Convert the input to a masked array, conserving subclasses. |
| 8679 | |
| 8680 | If `a` is a subclass of `MaskedArray`, its class is conserved. |
| 8681 | No copy is performed if the input is already an `ndarray`. |
| 8682 | |
| 8683 | Parameters |
| 8684 | ---------- |
| 8685 | a : array_like |
| 8686 | Input data, in any form that can be converted to an array. |
| 8687 | dtype : dtype, optional |
| 8688 | By default, the data-type is inferred from the input data. |
| 8689 | order : {'C', 'F', 'A', 'K'}, optional |
| 8690 | Memory layout. 'A' and 'K' depend on the order of input array ``a``. |
| 8691 | 'C' row-major (C-style), |
| 8692 | 'F' column-major (Fortran-style) memory representation. |
| 8693 | 'A' (any) means 'F' if ``a`` is Fortran contiguous, 'C' otherwise |
| 8694 | 'K' (keep) preserve input order |
| 8695 | Defaults to 'K'. |
| 8696 | |
| 8697 | Returns |
| 8698 | ------- |
| 8699 | out : MaskedArray |
| 8700 | MaskedArray interpretation of `a`. |
| 8701 | |
| 8702 | See Also |
| 8703 | -------- |
| 8704 | asarray : Similar to `asanyarray`, but does not conserve subclass. |
| 8705 | |
| 8706 | Examples |
| 8707 | -------- |
| 8708 | >>> import numpy as np |
| 8709 | >>> x = np.arange(10.).reshape(2, 5) |
| 8710 | >>> x |
| 8711 | array([[0., 1., 2., 3., 4.], |
| 8712 | [5., 6., 7., 8., 9.]]) |
| 8713 | >>> np.ma.asanyarray(x) |
| 8714 | masked_array( |
| 8715 | data=[[0., 1., 2., 3., 4.], |
| 8716 | [5., 6., 7., 8., 9.]], |
| 8717 | mask=False, |
| 8718 | fill_value=1e+20) |
| 8719 | >>> type(np.ma.asanyarray(x)) |
| 8720 | <class 'numpy.ma.MaskedArray'> |
| 8721 | |
| 8722 | """ |
| 8723 | # workaround for #8666, to preserve identity. Ideally the bottom line |
| 8724 | # would handle this for us. |
| 8725 | if ( |
| 8726 | isinstance(a, MaskedArray) |
| 8727 | and (dtype is None or dtype == a.dtype) |
| 8728 | and ( |
| 8729 | order in {None, 'A', 'K'} |
| 8730 | or order == 'C' and a.flags.carray |
| 8731 | or order == 'F' and a.flags.f_contiguous |
| 8732 | ) |
| 8733 | ): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…