# xarray.DataArray.copy

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

Return 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.

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

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('eebce0f9-3672-4659-bb1e-a6992f897882','00ab54e4-28aa-4111-817d-3a128e9fb90d','6f19f61f-6915-4d89-bda3-b5055a2c33d6','../lite/tree/../notebooks/index.html?path=fd0e81b1_02f9_4a3b_bff1_e489e4765a7e.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="6f19f61f-6915-4d89-bda3-b5055a2c33d6" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('eebce0f9-3672-4659-bb1e-a6992f897882','6f19f61f-6915-4d89-bda3-b5055a2c33d6')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('eebce0f9-3672-4659-bb1e-a6992f897882','6f19f61f-6915-4d89-bda3-b5055a2c33d6')">Open In Tab</button></div><div id="00ab54e4-28aa-4111-817d-3a128e9fb90d" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
