dev-resources.site
for different kinds of informations.
any in PyTorch
Published at
12/31/2024
Categories
python
pytorch
any
function
Author
hyperkai
Main Article
Author
8 person written this
hyperkai
open
any() can check if any elements of a 0D or more D tensor are True
, getting the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
any()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
orbool
). - The 2nd argument with
torch
or the 1st argument with a tensor isdim
(Optional-Type:int
,tuple
ofint
orlist
ofint
). - The 3rd argument with
torch
or the 2nd argument with a tensor iskeepdim
(Optional-Default:False
-Type:bool
). *My post explainskeepdim
argument. - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. -
My post explains
out
argument.
-
- An empty tensor returns a
False
of a 1D or more D tensor or an empty 1D or more D tensor.
import torch
my_tensor = torch.tensor(True)
torch.any(input=my_tensor)
my_tensor.any()
torch.any(input=my_tensor, dim=0)
torch.any(input=my_tensor, dim=-1)
torch.any(input=my_tensor, dim=(0,))
torch.any(input=my_tensor, dim=(-1,))
# tensor(True)
torch.any(input=my_tensor, dim=0, keepdim=True)
# tensor(True)
my_tensor = torch.tensor([True, False, True, False])
torch.any(input=my_tensor)
torch.any(input=my_tensor, dim=0)
torch.any(input=my_tensor, dim=-1)
torch.any(input=my_tensor, dim=(0,))
torch.any(input=my_tensor, dim=(-1,))
# tensor(True)
torch.any(input=my_tensor, dim=0, keepdim=True)
# tensor([True])
my_tensor = torch.tensor([[True, False, True, False],
[True, False, True, False]])
torch.any(input=my_tensor)
torch.any(input=my_tensor, dim=(0, 1))
torch.any(input=my_tensor, dim=(0, -1))
torch.any(input=my_tensor, dim=(1, 0))
torch.any(input=my_tensor, dim=(1, -2))
torch.any(input=my_tensor, dim=(-1, 0))
torch.any(input=my_tensor, dim=(-1, -2))
torch.any(input=my_tensor, dim=(-2, 1))
torch.any(input=my_tensor, dim=(-2, -1))
# tensor(True)
torch.any(input=my_tensor, dim=0)
torch.any(input=my_tensor, dim=(0,))
torch.any(input=my_tensor, dim=-2)
# tensor([True, False, True, False])
torch.any(input=my_tensor, dim=1)
torch.any(input=my_tensor, dim=-1)
torch.any(input=my_tensor, dim=(-1,))
# tensor([True, True])
torch.any(input=my_tensor, dim=0, keepdim=True)
# tensor([[True, False, True, False]])
my_tensor = torch.tensor([[0, 1, 2, 3],
[4, 5, 6, 7]])
torch.any(input=my_tensor)
# tensor(True)
my_tensor = torch.tensor([[0., 1., 2., 3.],
[4., 5., 6., 7.]])
torch.any(input=my_tensor)
# tensor(True)
my_tensor = torch.tensor([[0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j],
[4.+0.j, 5.+0.j, 6.+0.j, 7.+0.j]])
torch.any(input=my_tensor)
# tensor(True)
my_tensor = torch.tensor([[]])
torch.any(input=my_tensor)
# tensor(False)
torch.any(input=my_tensor, dim=0)
torch.any(input=my_tensor, dim=-2)
# tensor([], dtype=torch.bool)
torch.any(input=my_tensor, dim=1)
torch.any(input=my_tensor, dim=-1)
# tensor([False])
pytorch Article's
30 articles in total
Face Recognition with Python and FaceNet
read article
RandomAffine in PyTorch
read article
CocoCaptions in PyTorch (2)
read article
CocoDetection in PyTorch (3)
read article
CocoDetection in PyTorch (2)
read article
square in PyTorch
read article
any in PyTorch
currently reading
atleast_2d in PyTorch
read article
atleast_1d in PyTorch
read article
atleast_3d in PyTorch
read article
fmod in PyTorch
read article
remainder in PyTorch
read article
sub in PyTorch
read article
mul in PyTorch
read article
linspace in PyTorch
read article
arange in PyTorch
read article
unsqueeze in PyTorch
read article
squeeze in PyTorch
read article
all in PyTorch
read article
ColorJitter in PyTorch
read article
ImageNet in PyTorch
read article
Asynchronous Python: What You Need to Know ๐๐๐
read article
Install PyTorch and JupyterLab on Ubuntu
read article
Datasets for Computer Vision (5)
read article
AI Pronunciation Trainer
read article
CocoCaptions in PyTorch (1)
read article
CocoCaptions in PyTorch (3)
read article
CocoDetection in PyTorch (1)
read article
pow in PyTorch
read article
Why PyTorch Stole the Spotlight from TensorFlow?
read article
Featured ones: