# 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('ad9df410-53fa-41c4-9826-254a8f79d2e1','1448b629-0e09-4a9e-abf8-a6133b66c6a7','3a664e82-4d53-4003-8852-0a0a3c3c5888','../lite/tree/../notebooks/index.html?path=da591d86_df55_4923_b609_03a5967057c5.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="3a664e82-4d53-4003-8852-0a0a3c3c5888" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('ad9df410-53fa-41c4-9826-254a8f79d2e1','3a664e82-4d53-4003-8852-0a0a3c3c5888')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('ad9df410-53fa-41c4-9826-254a8f79d2e1','3a664e82-4d53-4003-8852-0a0a3c3c5888')">Open In Tab</button></div><div id="1448b629-0e09-4a9e-abf8-a6133b66c6a7" 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)
