tensor
¤
Classes:
| Name | Description |
|---|---|
Tensor |
A wrapper around an xr.DataArray for better integration with bioimageio.spec |
Tensor
¤
Bases: MagicTensorOpsMixin
flowchart TD
bioimageio.core.tensor.Tensor[Tensor]
bioimageio.core._magic_tensor_ops.MagicTensorOpsMixin[MagicTensorOpsMixin]
bioimageio.core._magic_tensor_ops.MagicTensorOpsMixin --> bioimageio.core.tensor.Tensor
click bioimageio.core.tensor.Tensor href "" "bioimageio.core.tensor.Tensor"
click bioimageio.core._magic_tensor_ops.MagicTensorOpsMixin href "" "bioimageio.core._magic_tensor_ops.MagicTensorOpsMixin"
A wrapper around an xr.DataArray for better integration with bioimageio.spec and improved type annotations.
-
API Reference
ioload_tensor
Methods:
| Name | Description |
|---|---|
__abs__ |
|
__add__ |
|
__and__ |
|
__array__ |
|
__eq__ |
|
__floordiv__ |
|
__ge__ |
|
__getitem__ |
|
__gt__ |
|
__iadd__ |
|
__iand__ |
|
__ifloordiv__ |
|
__ilshift__ |
|
__imod__ |
|
__imul__ |
|
__invert__ |
|
__ior__ |
|
__ipow__ |
|
__irshift__ |
|
__isub__ |
|
__iter__ |
|
__itruediv__ |
|
__ixor__ |
|
__le__ |
|
__len__ |
|
__lshift__ |
|
__lt__ |
|
__mod__ |
|
__mul__ |
|
__ne__ |
|
__neg__ |
|
__or__ |
|
__pos__ |
|
__pow__ |
|
__radd__ |
|
__rand__ |
|
__repr__ |
|
__rfloordiv__ |
|
__rmod__ |
|
__rmul__ |
|
__ror__ |
|
__rpow__ |
|
__rshift__ |
|
__rsub__ |
|
__rtruediv__ |
|
__rxor__ |
|
__setitem__ |
|
__sub__ |
|
__truediv__ |
|
__xor__ |
|
argmax |
|
argsort |
|
assign_batch_multi_index |
Set the batch multi-index for this tensor. |
astype |
Return tensor cast to |
clip |
Return a tensor whose values are limited to [min, max]. |
conj |
|
conjugate |
|
crop_to |
crop to match |
expand_dims |
|
from_numpy |
create a |
from_xarray |
create a |
item |
Copy a tensor element to a standard Python scalar and return it. |
mean |
|
pad |
|
pad_to |
pad |
quantile |
|
resize_to |
return cropped/padded tensor with |
round |
|
std |
|
sum |
Reduce this Tensor's data by applying sum along some dimension(s). |
to_numpy |
Return the data of this tensor as a numpy array. |
transpose |
Return a transposed tensor, missing axes are expanded (if |
unstack_batch_multi_index |
Unstack the batch multi-index of this tensor. |
var |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__hash__ |
None
|
|
__slots__ |
|
|
data |
|
|
dims |
Tuple of dimension names associated with this tensor. |
|
dtype |
DTypeStr
|
|
ndim |
Number of tensor dimensions. |
|
shape |
Tuple of tensor axes lengths |
|
shape_tuple |
Tuple of tensor axes lengths |
|
size |
Number of elements in the tensor. |
|
sizes |
Ordered, immutable mapping from axis ids to axis lengths. |
|
tagged_shape |
(alias for |
Source code in src/bioimageio/core/tensor.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
size
property
¤
size
Number of elements in the tensor.
Equal to math.prod(tensor.shape), i.e., the product of the tensors’ dimensions.
tagged_shape
property
¤
tagged_shape
(alias for sizes) Ordered, immutable mapping from axis ids to lengths.
__abs__
¤
__abs__() -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
175 176 | |
__add__
¤
__add__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
31 32 | |
__and__
¤
__and__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
52 53 | |
__array__
¤
__array__(dtype: DTypeLike = None)
Source code in src/bioimageio/core/tensor.py
93 94 | |
__eq__
¤
__eq__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
79 80 81 82 83 | |
__floordiv__
¤
__floordiv__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
46 47 | |
__ge__
¤
__ge__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
76 77 | |
__getitem__
¤
__getitem__(key: Union[SliceInfo, slice, int, PerAxis[Union[SliceInfo, slice, int]], Tensor, xr.DataArray]) -> Self
Source code in src/bioimageio/core/tensor.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
__gt__
¤
__gt__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
73 74 | |
__iadd__
¤
__iadd__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
130 131 | |
__iand__
¤
__iand__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
151 152 | |
__ifloordiv__
¤
__ifloordiv__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
145 146 | |
__ilshift__
¤
__ilshift__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
160 161 | |
__imod__
¤
__imod__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
148 149 | |
__imul__
¤
__imul__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
136 137 | |
__invert__
¤
__invert__() -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
178 179 | |
__ior__
¤
__ior__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
157 158 | |
__ipow__
¤
__ipow__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
139 140 | |
__irshift__
¤
__irshift__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
163 164 | |
__isub__
¤
__isub__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
133 134 | |
__iter__
¤
__iter__() -> Iterator[Any]
Source code in src/bioimageio/core/tensor.py
143 144 145 146 | |
__itruediv__
¤
__itruediv__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
142 143 | |
__ixor__
¤
__ixor__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
154 155 | |
__le__
¤
__le__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
70 71 | |
__len__
¤
__len__() -> int
Source code in src/bioimageio/core/tensor.py
136 137 | |
__lshift__
¤
__lshift__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
61 62 | |
__lt__
¤
__lt__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
67 68 | |
__mod__
¤
__mod__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
49 50 | |
__mul__
¤
__mul__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
37 38 | |
__ne__
¤
__ne__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
85 86 87 88 89 | |
__neg__
¤
__neg__() -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
169 170 | |
__or__
¤
__or__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
58 59 | |
__pos__
¤
__pos__() -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
172 173 | |
__pow__
¤
__pow__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
40 41 | |
__radd__
¤
__radd__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
95 96 | |
__rand__
¤
__rand__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
116 117 | |
__repr__
¤
__repr__() -> str
Source code in src/bioimageio/core/tensor.py
90 91 | |
__rfloordiv__
¤
__rfloordiv__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
110 111 | |
__rmod__
¤
__rmod__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
113 114 | |
__rmul__
¤
__rmul__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
101 102 | |
__ror__
¤
__ror__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
122 123 | |
__rpow__
¤
__rpow__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
104 105 | |
__rshift__
¤
__rshift__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
64 65 | |
__rsub__
¤
__rsub__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
98 99 | |
__rtruediv__
¤
__rtruediv__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
107 108 | |
__rxor__
¤
__rxor__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
119 120 | |
__setitem__
¤
__setitem__(key: Union[PerAxis[Union[SliceInfo, slice]], Tensor, xr.DataArray], value: Union[Tensor, xr.DataArray, float, int]) -> None
Source code in src/bioimageio/core/tensor.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
__sub__
¤
__sub__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
34 35 | |
__truediv__
¤
__truediv__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
43 44 | |
__xor__
¤
__xor__(other: _Compatible) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
55 56 | |
argmax
¤
argmax() -> Mapping[AxisId, int]
Source code in src/bioimageio/core/tensor.py
283 284 285 286 | |
argsort
¤
argsort(*args: Any, **kwargs: Any) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
188 189 190 191 192 193 | |
assign_batch_multi_index
¤
assign_batch_multi_index(multi_index: 'pd.MultiIndex') -> Self
Set the batch multi-index for this tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
'pd.MultiIndex'
|
The multi-index to set. |
required |
Source code in src/bioimageio/core/tensor.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
astype
¤
astype(dtype: DTypeStr, *, copy: bool = False)
Return tensor cast to dtype
note: if dtype is already satisfied copy if copy
Source code in src/bioimageio/core/tensor.py
288 289 290 291 292 | |
clip
¤
clip(min: Optional[float] = None, max: Optional[float] = None)
Return a tensor whose values are limited to [min, max]. At least one of max or min must be given.
Source code in src/bioimageio/core/tensor.py
294 295 296 297 | |
conj
¤
conj(*args: Any, **kwargs: Any) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
195 196 197 198 199 200 | |
conjugate
¤
conjugate(*args: Any, **kwargs: Any) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
202 203 204 205 206 207 | |
crop_to
¤
crop_to(sizes: PerAxis[int], crop_where: Union[CropWhere, PerAxis[CropWhere]] = 'left_and_right') -> Self
crop to match sizes
Source code in src/bioimageio/core/tensor.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
expand_dims
¤
Source code in src/bioimageio/core/tensor.py
344 345 | |
from_numpy
classmethod
¤
create a Tensor from a numpy array
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
NDArray[Any]
|
the nd numpy array |
required |
|
Optional[Union[AxisLike, Sequence[AxisLike]]]
|
A description of the array's axes. If None axes are guessed (which might fail and raise a ValueError.) If dims do not match array shape, permutations and singleton dimensions are tried to find a match. |
required |
Raises:
ValueError: if dims is None and dims guessing fails.
Source code in src/bioimageio/core/tensor.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
from_xarray
classmethod
¤
from_xarray(data_array: xr.DataArray) -> Self
create a Tensor from an xarray data array
this factory method is round-trip save
for any Tensor's data property (an xarray.DataArray).
Source code in src/bioimageio/core/tensor.py
186 187 188 189 190 191 192 193 | |
item
¤
Copy a tensor element to a standard Python scalar and return it.
Source code in src/bioimageio/core/tensor.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
mean
¤
Source code in src/bioimageio/core/tensor.py
362 363 | |
pad
¤
pad(pad_width: PerAxis[PadWidthLike], mode: PadMode = 'symmetric') -> Self
Source code in src/bioimageio/core/tensor.py
365 366 367 368 369 370 371 372 373 374 375 376 | |
pad_to
¤
pad_to(sizes: PerAxis[int], pad_where: Union[PadWhere, PerAxis[PadWhere]] = 'left_and_right', mode: PadMode = 'symmetric') -> Self
pad tensor to match sizes
Source code in src/bioimageio/core/tensor.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
quantile
¤
quantile(q: Union[float, Sequence[float]], dim: Optional[Union[AxisId, Sequence[AxisId]]] = None, method: QuantileMethod = 'linear') -> Self
Source code in src/bioimageio/core/tensor.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
resize_to
¤
resize_to(sizes: PerAxis[int], *, pad_where: Union[PadWhere, PerAxis[PadWhere]] = 'left_and_right', crop_where: Union[CropWhere, PerAxis[CropWhere]] = 'left_and_right', pad_mode: PadMode = 'symmetric')
return cropped/padded tensor with sizes
Source code in src/bioimageio/core/tensor.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
round
¤
round(*args: Any, **kwargs: Any) -> Self
Source code in src/bioimageio/core/_magic_tensor_ops.py
181 182 183 184 185 186 | |
std
¤
Source code in src/bioimageio/core/tensor.py
485 486 | |
sum
¤
Reduce this Tensor's data by applying sum along some dimension(s).
Source code in src/bioimageio/core/tensor.py
488 489 490 | |
to_numpy
¤
to_numpy() -> NDArray[Any]
Return the data of this tensor as a numpy array.
Source code in src/bioimageio/core/tensor.py
279 280 281 | |
transpose
¤
transpose(axes: Sequence[AxisId], *, extra_dims: Literal['raise', 'squeeze', 'stack', 'squeeze_or_stack'] = 'squeeze', missing_dims: Literal['raise', 'expand', 'unstack', 'unstack_or_expand'] = 'unstack_or_expand') -> Self
Return a transposed tensor, missing axes are expanded (if unstack_missing_dims_from_batch is False) or unstacked from batch (if unstack_missing_dims_from_batch is True), extra axes are stacked to batch (if stack_extra_dims_to_batch is True). Additional axes raise (if stack_extra_dims_to_batch is True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Sequence[AxisId]
|
The desired tensor axes |
required |
|
Literal['raise', 'squeeze', 'stack', 'squeeze_or_stack']
|
Extra dimensions are any dimensions in the tensor that are not specified in |
'squeeze'
|
|
Literal['raise', 'expand', 'unstack', 'unstack_or_expand']
|
Missing dimensions are any dimensions specified in |
'unstack_or_expand'
|
Source code in src/bioimageio/core/tensor.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
unstack_batch_multi_index
¤
unstack_batch_multi_index(*, errors: Literal['raise', 'ignore'] = 'raise') -> Self
Unstack the batch multi-index of this tensor.
Returns:
| Type | Description |
|---|---|
Self
|
A new tensor with the batch multi-index unstacked into separate axes. |
Source code in src/bioimageio/core/tensor.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |