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')
| 1916 | |
| 1917 | @array_function_dispatch(_ravel_dispatcher) |
| 1918 | def 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 |
searching dependent graphs…