Tensor operations with mask for PyTorch.
Project description
torchmasked
Tensor operations with mask for PyTorch.
Sometimes you need to perform operations on tensors with the masked elements been ignored, for example:
>>> input = torch.tensor([1., 2., 3.])
>>> result = torch.sum(input)
>>> print(result)
tensor(6.)
>>> mask = torch.tensor([1, 1, 0]).byte()
>>> masked_result = torchmasked.masked_sum(input, mask)
>>> print(masked_result)
tensor(3.) # element input[2] is masked and ignored
Then this package could be helpful.
Installation
From source:
pip install git+https://github.com/Renovamen/torchmasked.git --upgrade
# or
python setup.py install
Supported Operations
- max (masked version of
torch.max
) - min (
torch.min
) - sum (
torch.sum
) - mean (
torch.mean
) - softmax (
torch.nn.functional.softmax
andtorch.nn.Softmax
)
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torchmasked-0.1.0.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for torchmasked-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6b80a29b3534cfa19681825b1bd31ea7ed38737f7daa059ee118bb7d6ca1bbc |
|
MD5 | 920b3ad519a557e09e6e776889c23b88 |
|
BLAKE2b-256 | 629b405c9d93a6c1f915c1b52bd3e06519bf08abb7f8179232b2c2de3b64c522 |