MCPcopy Create free account
hub / github.com/numpy/numpy / ravel

Method ravel

numpy/ma/core.py:4624–4683  ·  view source on GitHub ↗

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')

Source from the content-addressed store, hash-verified

4622 return (~m).sum(axis=axis, dtype=np.intp, **kwargs)
4623
4624 def ravel(self, order='C'):
4625 """
4626 Returns a 1D version of self, as a view.
4627
4628 Parameters
4629 ----------
4630 order : {'C', 'F', 'A', 'K'}, optional
4631 The elements of `a` are read using this index order. 'C' means to
4632 index the elements in C-like order, with the last axis index
4633 changing fastest, back to the first axis index changing slowest.
4634 'F' means to index the elements in Fortran-like index order, with
4635 the first index changing fastest, and the last index changing
4636 slowest. Note that the 'C' and 'F' options take no account of the
4637 memory layout of the underlying array, and only refer to the order
4638 of axis indexing. 'A' means to read the elements in Fortran-like
4639 index order if `m` is Fortran *contiguous* in memory, C-like order
4640 otherwise. 'K' means to read the elements in the order they occur
4641 in memory, except for reversing the data when strides are negative.
4642 By default, 'C' index order is used.
4643 (Masked arrays currently use 'A' on the data when 'K' is passed.)
4644
4645 Returns
4646 -------
4647 MaskedArray
4648 Output view is of shape ``(self.size,)`` (or
4649 ``(np.ma.product(self.shape),)``).
4650
4651 Examples
4652 --------
4653 >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
4654 >>> x
4655 masked_array(
4656 data=[[1, --, 3],
4657 [--, 5, --],
4658 [7, --, 9]],
4659 mask=[[False, True, False],
4660 [ True, False, True],
4661 [False, True, False]],
4662 fill_value=999999)
4663 >>> x.ravel()
4664 masked_array(data=[1, --, 3, --, 5, --, 7, --, 9],
4665 mask=[False, True, False, True, False, True, False, True,
4666 False],
4667 fill_value=999999)
4668
4669 """
4670 # The order of _data and _mask could be different (it shouldn't be
4671 # normally). Passing order `K` or `A` would be incorrect.
4672 # So we ignore the mask memory order.
4673 # TODO: We don't actually support K, so use A instead. We could
4674 # try to guess this correct by sorting strides or deprecate.
4675 if order in "kKaA":
4676 order = "F" if self._data.flags.fnc else "C"
4677 r = ndarray.ravel(self._data, order=order).view(type(self))
4678 r._update_from(self)
4679 if self._mask is not nomask:
4680 r._mask = ndarray.ravel(self._mask, order=order).reshape(r.shape)
4681 else:

Callers 15

flatMethod · 0.95
uniform32_from_uint64Function · 0.45
ravelFunction · 0.45
flatnonzeroFunction · 0.45
outerFunction · 0.45
rollFunction · 0.45
test_ravel_with_orderMethod · 0.45
test_method_argsMethod · 0.45
test_attributesMethod · 0.45

Calls 3

_update_fromMethod · 0.80
reshapeMethod · 0.80
viewMethod · 0.45