deepmr.resize#
- deepmr.resize(input, oshape)[source]#
Resize with zero-padding or cropping.
Adapted from SigPy [1].
- Parameters:
input (np.ndarray | torch.Tensor) – Input tensor of shape
(..., ishape)
.oshape (Iterable) – Output shape.
- Returns:
output – Zero-padded or cropped tensor of shape
(..., oshape)
.- Return type:
np.ndarray | torch.Tensor
Examples
>>> import torch >>> import deepmr
We can pad tensors to desired shape:
>>> x = torch.tensor([0, 1, 0]) >>> y = deepmr.resize(x, [5]) >>> y tensor([0, 0, 1, 0, 0])
Batch dimensions are automatically expanded (pad will be applied starting from rightmost dimension):
>>> x = torch.tensor([0, 1, 0])[None, ...] >>> x.shape torch.Size([1, 3]) >>> y = deepmr.resize(x, [5]) # len(oshape) == 1 >>> y.shape torch.Size([1, 5])
Similarly, if oshape is smaller than ishape, the tensor will be cropped:
>>> x = torch.tensor([0, 0, 1, 0, 0]) >>> y = deepmr.resize(x, [3]) >>> y tensor([0, 1, 0])
Again, batch dimensions are automatically expanded:
>>> x = torch.tensor([0, 0, 1, 0, 0])[None, ...] >>> x.shape torch.Size([1, 5]) >>> y = deepmr.resize(x, [3]) # len(oshape) == 1 >>> y.shape torch.Size([1, 3])
References
[1] mikgroup/sigpy