Concatenate strings elementwise in the DataArray with other strings. The other strings can either be string scalars or other array-like. Dimensions are automatically broadcast together. An optional separator `sep` can also be specified. If `sep` is array-li
(self, *others, sep: str | bytes | Any = "")
| 432 | return self._apply(func=func, func_args=(start, stop, repl)) |
| 433 | |
| 434 | def cat(self, *others, sep: str | bytes | Any = "") -> T_DataArray: |
| 435 | """ |
| 436 | Concatenate strings elementwise in the DataArray with other strings. |
| 437 | |
| 438 | The other strings can either be string scalars or other array-like. |
| 439 | Dimensions are automatically broadcast together. |
| 440 | |
| 441 | An optional separator `sep` can also be specified. If `sep` is |
| 442 | array-like, it is broadcast against the array and applied elementwise. |
| 443 | |
| 444 | Parameters |
| 445 | ---------- |
| 446 | *others : str or array-like of str |
| 447 | Strings or array-like of strings to concatenate elementwise with |
| 448 | the current DataArray. |
| 449 | sep : str or array-like of str, default: "". |
| 450 | Separator to use between strings. |
| 451 | It is broadcast in the same way as the other input strings. |
| 452 | If array-like, its dimensions will be placed at the end of the output array dimensions. |
| 453 | |
| 454 | Returns |
| 455 | ------- |
| 456 | concatenated : same type as values |
| 457 | |
| 458 | Examples |
| 459 | -------- |
| 460 | Create a string array |
| 461 | |
| 462 | >>> myarray = xr.DataArray( |
| 463 | ... ["11111", "4"], |
| 464 | ... dims=["X"], |
| 465 | ... ) |
| 466 | |
| 467 | Create some arrays to concatenate with it |
| 468 | |
| 469 | >>> values_1 = xr.DataArray( |
| 470 | ... ["a", "bb", "cccc"], |
| 471 | ... dims=["Y"], |
| 472 | ... ) |
| 473 | >>> values_2 = np.array(3.4) |
| 474 | >>> values_3 = "" |
| 475 | >>> values_4 = np.array("test", dtype=np.str_) |
| 476 | |
| 477 | Determine the separator to use |
| 478 | |
| 479 | >>> seps = xr.DataArray( |
| 480 | ... [" ", ", "], |
| 481 | ... dims=["ZZ"], |
| 482 | ... ) |
| 483 | |
| 484 | Concatenate the arrays using the separator |
| 485 | |
| 486 | >>> myarray.str.cat(values_1, values_2, values_3, values_4, sep=seps) |
| 487 | <xarray.DataArray (X: 2, Y: 3, ZZ: 2)> Size: 1kB |
| 488 | array([[['11111 a 3.4 test', '11111, a, 3.4, , test'], |
| 489 | ['11111 bb 3.4 test', '11111, bb, 3.4, , test'], |
| 490 | ['11111 cccc 3.4 test', '11111, cccc, 3.4, , test']], |
| 491 | <BLANKLINE> |