Return an array copy of the given object. Parameters ---------- a : array_like Input data. order : {'C', 'F', 'A', 'K'}, optional Controls the memory layout of the copy. 'C' means C-order, 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
(a, order='K', subok=False)
| 872 | |
| 873 | @array_function_dispatch(_copy_dispatcher) |
| 874 | def copy(a, order='K', subok=False): |
| 875 | """ |
| 876 | Return an array copy of the given object. |
| 877 | |
| 878 | Parameters |
| 879 | ---------- |
| 880 | a : array_like |
| 881 | Input data. |
| 882 | order : {'C', 'F', 'A', 'K'}, optional |
| 883 | Controls the memory layout of the copy. 'C' means C-order, |
| 884 | 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, |
| 885 | 'C' otherwise. 'K' means match the layout of `a` as closely |
| 886 | as possible. (Note that this function and :meth:`ndarray.copy` are very |
| 887 | similar, but have different default values for their order= |
| 888 | arguments.) |
| 889 | subok : bool, optional |
| 890 | If True, then sub-classes will be passed-through, otherwise the |
| 891 | returned array will be forced to be a base-class array (defaults to False). |
| 892 | |
| 893 | .. versionadded:: 1.19.0 |
| 894 | |
| 895 | Returns |
| 896 | ------- |
| 897 | arr : ndarray |
| 898 | Array interpretation of `a`. |
| 899 | |
| 900 | See Also |
| 901 | -------- |
| 902 | ndarray.copy : Preferred method for creating an array copy |
| 903 | |
| 904 | Notes |
| 905 | ----- |
| 906 | This is equivalent to: |
| 907 | |
| 908 | >>> np.array(a, copy=True) #doctest: +SKIP |
| 909 | |
| 910 | Examples |
| 911 | -------- |
| 912 | Create an array x, with a reference y and a copy z: |
| 913 | |
| 914 | >>> x = np.array([1, 2, 3]) |
| 915 | >>> y = x |
| 916 | >>> z = np.copy(x) |
| 917 | |
| 918 | Note that, when we modify x, y changes, but not z: |
| 919 | |
| 920 | >>> x[0] = 10 |
| 921 | >>> x[0] == y[0] |
| 922 | True |
| 923 | >>> x[0] == z[0] |
| 924 | False |
| 925 | |
| 926 | Note that, np.copy clears previously set WRITEABLE=False flag. |
| 927 | |
| 928 | >>> a = np.array([1, 2, 3]) |
| 929 | >>> a.flags["WRITEABLE"] = False |
| 930 | >>> b = np.copy(a) |
| 931 | >>> b.flags["WRITEABLE"] |
no test coverage detected