MCPcopy
hub / github.com/numpy/numpy / ravel

Function ravel

numpy/_core/fromnumeric.py:1918–2024  ·  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

1916
1917@array_function_dispatch(_ravel_dispatcher)
1918def ravel(a, order='C'):
1919 """Return a contiguous flattened array.
1920
1921 A 1-D array, containing the elements of the input, is returned. A copy is
1922 made only if needed.
1923
1924 As of NumPy 1.10, the returned array will have the same type as the input
1925 array. (for example, a masked array will be returned for a masked array
1926 input)
1927
1928 Parameters
1929 ----------
1930 a : array_like
1931 Input array. The elements in `a` are read in the order specified by
1932 `order`, and packed as a 1-D array.
1933 order : {'C','F', 'A', 'K'}, optional
1934
1935 The elements of `a` are read using this index order. 'C' means
1936 to index the elements in row-major, C-style order,
1937 with the last axis index changing fastest, back to the first
1938 axis index changing slowest. 'F' means to index the elements
1939 in column-major, Fortran-style order, with the
1940 first index changing fastest, and the last index changing
1941 slowest. Note that the 'C' and 'F' options take no account of
1942 the memory layout of the underlying array, and only refer to
1943 the order of axis indexing. 'A' means to read the elements in
1944 Fortran-like index order if `a` is Fortran *contiguous* in
1945 memory, C-like order otherwise. 'K' means to read the
1946 elements in the order they occur in memory, except for
1947 reversing the data when strides are negative. By default, 'C'
1948 index order is used.
1949
1950 Returns
1951 -------
1952 y : array_like
1953 y is a contiguous 1-D array of the same subtype as `a`,
1954 with shape ``(a.size,)``.
1955 Note that matrices are special cased for backward compatibility,
1956 if `a` is a matrix, then y is a 1-D ndarray.
1957
1958 See Also
1959 --------
1960 ndarray.flat : 1-D iterator over an array.
1961 ndarray.flatten : 1-D array copy of the elements of an array
1962 in row-major order.
1963 ndarray.reshape : Change the shape of an array without changing its data.
1964
1965 Notes
1966 -----
1967 In row-major, C-style order, in two dimensions, the row index
1968 varies the slowest, and the column index the quickest. This can
1969 be generalized to multiple dimensions, where row-major order
1970 implies that the index along the first axis varies slowest, and
1971 the index along the last quickest. The opposite holds for
1972 column-major, Fortran-style index ordering.
1973
1974 When a view is desired in as many cases as possible, ``arr.reshape(-1)``
1975 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…