# xarray.DataArray.copy

#### DataArray.copy(deep=True, data=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L1404-L1472)

Returns a copy of this array.

If deep=True, a deep copy is made of the data array.
Otherwise, a shallow copy is made, and the returned data array’s
values are a new view of this data array’s values.

Use data to create a new object with the same structure as
original but entirely new data.

* **Parameters:**
  * **deep** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *optional*) – Whether the data array and its coordinates are loaded into memory
    and copied onto the new object. Default is True.
  * **data** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like), *optional*) – Data to use in the new object. Must have same shape as original.
    When data is used, deep is ignored for all data variables,
    and only used for coords.
* **Returns:**
  **copy** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – New object with dimensions, attributes, coordinates, name,
  encoding, and optionally data copied from original.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('2354dd83-bae5-4d88-939c-02e8e8ae6186','b471c9e3-1e09-42f0-9fef-c07fb02ca578','8d0e219a-8c32-4d61-b31f-904189dfe6ac','../lite/tree/../notebooks/index.html?path=675e9a63_28a5_4e5d_a200_d38f21c3b3fb.ipynb','None')">Try it in your browser!</button></div>

Shallow versus deep copy

```pycon
>>> array = xr.DataArray([1, 2, 3], dims="x", coords={"x": ["a", "b", "c"]})
>>> array.copy()
<xarray.DataArray (x: 3)> Size: 24B
array([1, 2, 3])
Coordinates:
  * x        (x) <U1 12B 'a' 'b' 'c'
>>> array_0 = array.copy(deep=False)
>>> array_0[0] = 7
>>> array_0
<xarray.DataArray (x: 3)> Size: 24B
array([7, 2, 3])
Coordinates:
  * x        (x) <U1 12B 'a' 'b' 'c'
>>> array
<xarray.DataArray (x: 3)> Size: 24B
array([7, 2, 3])
Coordinates:
  * x        (x) <U1 12B 'a' 'b' 'c'
```

Changing the data using the `data` argument maintains the
structure of the original object, but with the new data. Original
object is unaffected.

```pycon
>>> array.copy(data=[0.1, 0.2, 0.3])
<xarray.DataArray (x: 3)> Size: 24B
array([0.1, 0.2, 0.3])
Coordinates:
  * x        (x) <U1 12B 'a' 'b' 'c'
>>> array
<xarray.DataArray (x: 3)> Size: 24B
array([7, 2, 3])
Coordinates:
  * x        (x) <U1 12B 'a' 'b' 'c'
```

<div id="8d0e219a-8c32-4d61-b31f-904189dfe6ac" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('2354dd83-bae5-4d88-939c-02e8e8ae6186','8d0e219a-8c32-4d61-b31f-904189dfe6ac')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('2354dd83-bae5-4d88-939c-02e8e8ae6186','8d0e219a-8c32-4d61-b31f-904189dfe6ac')">Open In Tab</button></div><div id="b471c9e3-1e09-42f0-9fef-c07fb02ca578" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`pandas.DataFrame.copy`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.copy.html#pandas.DataFrame.copy)
