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

Function ravel

numpy/core/fromnumeric.py:1769–1874  ·  view source on GitHub ↗

Return a contiguous flattened array. A 1-D array, containing the elements of the input, is returned. A copy is made only if needed. As of NumPy 1.10, the returned array will have the same type as the input array. (for example, a masked array will be returned for a masked array

(a, order='C')

Source from the content-addressed store, hash-verified

1767
1768@array_function_dispatch(_ravel_dispatcher)
1769def ravel(a, order='C'):
1770 """Return a contiguous flattened array.
1771
1772 A 1-D array, containing the elements of the input, is returned. A copy is
1773 made only if needed.
1774
1775 As of NumPy 1.10, the returned array will have the same type as the input
1776 array. (for example, a masked array will be returned for a masked array
1777 input)
1778
1779 Parameters
1780 ----------
1781 a : array_like
1782 Input array. The elements in `a` are read in the order specified by
1783 `order`, and packed as a 1-D array.
1784 order : {'C','F', 'A', 'K'}, optional
1785
1786 The elements of `a` are read using this index order. 'C' means
1787 to index the elements in row-major, C-style order,
1788 with the last axis index changing fastest, back to the first
1789 axis index changing slowest. 'F' means to index the elements
1790 in column-major, Fortran-style order, with the
1791 first index changing fastest, and the last index changing
1792 slowest. Note that the 'C' and 'F' options take no account of
1793 the memory layout of the underlying array, and only refer to
1794 the order of axis indexing. 'A' means to read the elements in
1795 Fortran-like index order if `a` is Fortran *contiguous* in
1796 memory, C-like order otherwise. 'K' means to read the
1797 elements in the order they occur in memory, except for
1798 reversing the data when strides are negative. By default, 'C'
1799 index order is used.
1800
1801 Returns
1802 -------
1803 y : array_like
1804 y is a contiguous 1-D array of the same subtype as `a`,
1805 with shape ``(a.size,)``.
1806 Note that matrices are special cased for backward compatibility,
1807 if `a` is a matrix, then y is a 1-D ndarray.
1808
1809 See Also
1810 --------
1811 ndarray.flat : 1-D iterator over an array.
1812 ndarray.flatten : 1-D array copy of the elements of an array
1813 in row-major order.
1814 ndarray.reshape : Change the shape of an array without changing its data.
1815
1816 Notes
1817 -----
1818 In row-major, C-style order, in two dimensions, the row index
1819 varies the slowest, and the column index the quickest. This can
1820 be generalized to multiple dimensions, where row-major order
1821 implies that the index along the first axis varies slowest, and
1822 the index along the last quickest. The opposite holds for
1823 column-major, Fortran-style index ordering.
1824
1825 When a view is desired in as many cases as possible, ``arr.reshape(-1)``
1826 may be preferable. However, ``ravel`` supports ``K`` in the optional

Callers 5

extractFunction · 0.90
appendFunction · 0.90
test_minmax_funcMethod · 0.90
resizeFunction · 0.85
test_testMinMaxMethod · 0.85

Calls 3

asanyarrayFunction · 0.85
asarrayFunction · 0.70
ravelMethod · 0.45

Tested by 2

test_minmax_funcMethod · 0.72
test_testMinMaxMethod · 0.68