Broadcast this DataArray against another Dataset or DataArray. This is equivalent to xr.broadcast(other, self)[1] xarray objects are broadcast against each other in arithmetic operations, so this method is not be necessary for most uses. If no change is needed, the
(
self,
other: T_DataArrayOrSet,
*,
exclude: Iterable[Hashable] | None = None,
)
| 1875 | return self._from_temp_dataset(ds) |
| 1876 | |
| 1877 | def broadcast_like( |
| 1878 | self, |
| 1879 | other: T_DataArrayOrSet, |
| 1880 | *, |
| 1881 | exclude: Iterable[Hashable] | None = None, |
| 1882 | ) -> Self: |
| 1883 | """Broadcast this DataArray against another Dataset or DataArray. |
| 1884 | |
| 1885 | This is equivalent to xr.broadcast(other, self)[1] |
| 1886 | |
| 1887 | xarray objects are broadcast against each other in arithmetic |
| 1888 | operations, so this method is not be necessary for most uses. |
| 1889 | |
| 1890 | If no change is needed, the input data is returned to the output |
| 1891 | without being copied. |
| 1892 | |
| 1893 | If new coords are added by the broadcast, their values are |
| 1894 | NaN filled. |
| 1895 | |
| 1896 | Parameters |
| 1897 | ---------- |
| 1898 | other : Dataset or DataArray |
| 1899 | Object against which to broadcast this array. |
| 1900 | exclude : iterable of Hashable, optional |
| 1901 | Dimensions that must not be broadcasted |
| 1902 | |
| 1903 | Returns |
| 1904 | ------- |
| 1905 | new_da : DataArray |
| 1906 | The caller broadcasted against ``other``. |
| 1907 | |
| 1908 | Examples |
| 1909 | -------- |
| 1910 | >>> arr1 = xr.DataArray( |
| 1911 | ... np.random.randn(2, 3), |
| 1912 | ... dims=("x", "y"), |
| 1913 | ... coords={"x": ["a", "b"], "y": ["a", "b", "c"]}, |
| 1914 | ... ) |
| 1915 | >>> arr2 = xr.DataArray( |
| 1916 | ... np.random.randn(3, 2), |
| 1917 | ... dims=("x", "y"), |
| 1918 | ... coords={"x": ["a", "b", "c"], "y": ["a", "b"]}, |
| 1919 | ... ) |
| 1920 | >>> arr1 |
| 1921 | <xarray.DataArray (x: 2, y: 3)> Size: 48B |
| 1922 | array([[ 1.76405235, 0.40015721, 0.97873798], |
| 1923 | [ 2.2408932 , 1.86755799, -0.97727788]]) |
| 1924 | Coordinates: |
| 1925 | * x (x) <U1 8B 'a' 'b' |
| 1926 | * y (y) <U1 12B 'a' 'b' 'c' |
| 1927 | >>> arr2 |
| 1928 | <xarray.DataArray (x: 3, y: 2)> Size: 48B |
| 1929 | array([[ 0.95008842, -0.15135721], |
| 1930 | [-0.10321885, 0.4105985 ], |
| 1931 | [ 0.14404357, 1.45427351]]) |
| 1932 | Coordinates: |
| 1933 | * x (x) <U1 12B 'a' 'b' 'c' |
| 1934 | * y (y) <U1 8B 'a' 'b' |