torch.masked_select

Introduction:

When studying the official documentation of pytorch, I found that the mask program was incorrectly posted, and I wrote one myself. You can refer to it.

torch.masked_select(input, mask, out=None) → Tensor

According maskto the binary value in the mask tensor , take the specified item in the input tensor (  maskByteTensor ), and return the value to a new 1D tensor,

The tensor  maskmust inputhave the same number of elements as the tensor, but the shape or dimension does not need to be the same.

Note: The returned tensor does not share memory space with the original tensor.

parameter:

  • input (Tensor) – input tensor
  • mask (ByteTensor) – mask tensor, containing binary index values
  • out (Tensor, optional) – target tensor
  • Experimental phenomena

  • x = torch.randn(3,4)
  • mask = torch.ByteTensor(x > 0)

  • torch.masked_select(x,mask)
  • Note: What is returned is exactly a one-dimensional tensor

 

 

Undertake programming in Matlab, Python and C++, machine learning, computer vision theory implementation and guidance, both undergraduate and master's degree, salted fish trading, professional answers please go to know, please contact QQ number 757160542 for details, if you are the one.

 

Guess you like

Origin blog.csdn.net/weixin_36670529/article/details/113817807