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

Function copy

numpy/lib/function_base.py:874–962  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

872
873@array_function_dispatch(_copy_dispatcher)
874def 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"]

Callers 8

count_run_Function · 0.50
merge_left_Function · 0.50
merge_right_Function · 0.50
merge_at_Function · 0.50
string_heapsort_Function · 0.50
mergesort0_Function · 0.50
string_quicksort_Function · 0.50
CCompiler_cxx_compilerFunction · 0.50

Calls 1

arrayFunction · 0.50

Tested by

no test coverage detected