Returns a 1D version of self, as a view. Parameters ---------- order : {'C', 'F', 'A', 'K'}, optional The elements of `a` are read using this index order. 'C' means to index the elements in C-like order, with the last axis index c
(self, order='C')
| 4688 | return (~m).sum(axis=axis, dtype=np.intp, **kwargs) |
| 4689 | |
| 4690 | def ravel(self, order='C'): |
| 4691 | """ |
| 4692 | Returns a 1D version of self, as a view. |
| 4693 | |
| 4694 | Parameters |
| 4695 | ---------- |
| 4696 | order : {'C', 'F', 'A', 'K'}, optional |
| 4697 | The elements of `a` are read using this index order. 'C' means to |
| 4698 | index the elements in C-like order, with the last axis index |
| 4699 | changing fastest, back to the first axis index changing slowest. |
| 4700 | 'F' means to index the elements in Fortran-like index order, with |
| 4701 | the first index changing fastest, and the last index changing |
| 4702 | slowest. Note that the 'C' and 'F' options take no account of the |
| 4703 | memory layout of the underlying array, and only refer to the order |
| 4704 | of axis indexing. 'A' means to read the elements in Fortran-like |
| 4705 | index order if `m` is Fortran *contiguous* in memory, C-like order |
| 4706 | otherwise. 'K' means to read the elements in the order they occur |
| 4707 | in memory, except for reversing the data when strides are negative. |
| 4708 | By default, 'C' index order is used. |
| 4709 | (Masked arrays currently use 'A' on the data when 'K' is passed.) |
| 4710 | |
| 4711 | Returns |
| 4712 | ------- |
| 4713 | MaskedArray |
| 4714 | Output view is of shape ``(self.size,)`` (or |
| 4715 | ``(np.ma.product(self.shape),)``). |
| 4716 | |
| 4717 | Examples |
| 4718 | -------- |
| 4719 | >>> import numpy as np |
| 4720 | >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) |
| 4721 | >>> x |
| 4722 | masked_array( |
| 4723 | data=[[1, --, 3], |
| 4724 | [--, 5, --], |
| 4725 | [7, --, 9]], |
| 4726 | mask=[[False, True, False], |
| 4727 | [ True, False, True], |
| 4728 | [False, True, False]], |
| 4729 | fill_value=999999) |
| 4730 | >>> x.ravel() |
| 4731 | masked_array(data=[1, --, 3, --, 5, --, 7, --, 9], |
| 4732 | mask=[False, True, False, True, False, True, False, True, |
| 4733 | False], |
| 4734 | fill_value=999999) |
| 4735 | |
| 4736 | """ |
| 4737 | # The order of _data and _mask could be different (it shouldn't be |
| 4738 | # normally). Passing order `K` or `A` would be incorrect. |
| 4739 | # So we ignore the mask memory order. |
| 4740 | # TODO: We don't actually support K, so use A instead. We could |
| 4741 | # try to guess this correct by sorting strides or deprecate. |
| 4742 | if order in "kKaA": |
| 4743 | order = "F" if self._data.flags.fnc else "C" |
| 4744 | r = ndarray.ravel(self._data, order=order).view(type(self)) |
| 4745 | r._update_from(self) |
| 4746 | if self._mask is not nomask: |
| 4747 | r._mask = ndarray.ravel(self._mask, order=order).reshape(r.shape) |