Logo

dev-resources.site

for different kinds of informations.

heaviside and Identity in PyTorch

Published at
8/16/2024
Categories
python
pytorch
heaviside
identity
Author
hyperkai
Categories
4 categories in total
python
open
pytorch
open
heaviside
open
identity
open
Author
8 person written this
hyperkai
open
heaviside and Identity in PyTorch

Buy Me a Coffee☕

*Memos:

heaviside() can get the 0D or more D tensor of the zero or more values computed by Heaviside step function from the 0D or more D tensor of zero or more elements as shown below:

*Memos:

  • heaviside() can be used with torch or a tensor.
  • The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float or bool).
  • The 2nd argument with torch or the 1st argument with a tensor is values(Required-Type:tensor of int, float or bool). Image description
import torch
from torch import nn

my_tensor = torch.tensor([8, -3, 0, 1, 5, -2, -1, 4])

torch.heaviside(input=my_tensor,
                values=torch.tensor(0))
my_tensor.heaviside(values=torch.tensor(0))
# tensor([1, 0, 0, 1, 1, 0, 0, 1])

torch.heaviside(input=my_tensor,
                values=torch.tensor([0, 1, 2, 3, 4, 5, 6, 7]))
# tensor([1, 0, 2, 1, 1, 0, 0, 1])

my_tensor = torch.tensor([[8, -3, 0, 1],
                          [5, 0, -1, 4]])
torch.heaviside(input=my_tensor, values=torch.tensor(0))
# tensor([[1, 0, 0, 1],
#         [1, 0, 0, 1]])

torch.heaviside(input=my_tensor,
                values=torch.tensor([[0, 1, 2, 3],
                                     [4, 5, 6, 7]]))
# tensor([[1, 0, 2, 1],
#         [1, 5, 0, 1]])

my_tensor = torch.tensor([[[8, -3], [0, 1]],
                          [[5, 0], [-1, 4]]])
torch.heaviside(input=my_tensor, values=torch.tensor(0))
# tensor([[[1, 0], [0, 1]],
#         [[1, 0], [0, 1]]])

torch.heaviside(input=my_tensor,
                values=torch.tensor([[[0, 1], [2, 3]],
                                     [[4, 5], [6, 7]]]))
# tensor([[[1, 0], [2, 1]],
#         [[1, 5], [0, 1]]])

my_tensor = torch.tensor([[[8., -3.], [0., 1.]],
                          [[5., 0.], [-1., 4.]]])
torch.heaviside(input=my_tensor,
                values=torch.tensor([[[0., 1.], [2., 3.]],
                                      [[4., 5.], [6., 7.]]]))
# tensor([[[1., 0.], [2., 1.]],
#         [[1., 5.], [0., 1.]]])

my_tensor = torch.tensor([[[True, False], [True, False]],
                          [[False, True], [False, True]]])
torch.heaviside(input=my_tensor,
                values=torch.tensor([[[True, False], [True, False]],
                                     [[False, True], [False, True]]]))
# tensor([[[True, False], [True, False]],
#         [[False, True], [False, True]]])
Enter fullscreen mode Exit fullscreen mode

Identity() can just get the same tensor as the input tensor which is the 0D or more D tensor of zero or more elements as shown below:
*Memos:

  • For initialization, you can set 0 or more arguments but there is no influence.
  • The 1st argument is input(Required-Type:tensor of int or float).

Image description

import torch
from torch import nn

my_tensor = torch.tensor([8, -3, 0, 1, 5, -2, -1, 4])

identity = nn.Identity()
identity(input=my_tensor)
# tensor([8, -3, 0, 1, 5, -2, -1, 4])

identity
# Identity()

identity = nn.Identity(num1=3, num2=5)
identity(input=my_tensor)
# tensor([8, -3, 0, 1, 5, -2, -1, 4])

my_tensor = torch.tensor([[8, -3, 0, 1],
                          [5, -2, -1, 4]])
identity = nn.Identity()
identity(input=my_tensor)
# tensor([[8, -3, 0, 1],
#         [5, -2, -1, 4]])

my_tensor = torch.tensor([[[8, -3], [0, 1]],
                          [[5, -2], [-1, 4]]])
identity = nn.Identity()
identity(input=my_tensor)
# tensor([[[8, -3], [0, 1]],
#         [[5, -2], [-1, 4]]])

my_tensor = torch.tensor([[[8., -3.], [0., 1.]],
                          [[5., -2.], [-1., 4.]]])
identity = nn.Identity()
identity(input=my_tensor)
# tensor([[[8., -3.], [0., 1.]],
#         [[5., -2.], [-1., 4.]]])
Enter fullscreen mode Exit fullscreen mode
identity Article's
30 articles in total
Favicon
Deploying and Configuring a Hybrid Identity Lab Using Bicep - Part 1: Active Directory Setup and Sync
Favicon
It’s cybersecurity’s kryptonite: Why are you still holding it?
Favicon
How to secure minimal api microservices with asp.net core identity
Favicon
How to verify NIN for Nigerians on the ecitizen platform.
Favicon
Simplified Configuration of SSO Profiles in AWS CLI Using SSO Sessions
Favicon
Google identity Platform
Favicon
Why Broken Links Are Costing You Brand Deals (And How to Fix It)
Favicon
How To Get There: Bridging The Technology Gap Preventing You From Adopting A Secrets-free Machine Identity Framework
Favicon
5 go-to-market lessons I learned from driving a developer-led growth product
Favicon
Revolutionizing Identity Resolution with Machine Learning: A Technical Overview
Favicon
Social Media Security: How to Protect Your Online Identity
Favicon
The Future of Web: How Web5 Transforms Identity and Data OwnerShip
Favicon
Private Self-Hosted OIDC AWS Authentication
Favicon
Opaque token vs JWT
Favicon
Implementing ASP.NET Identity for a Multi-Tenant Application: Best Practices
Favicon
Color palette in branding: How Logto generate a custom color scheme for your brand
Favicon
Concepts of a Ticket in ASP.NET Identity
Favicon
Understanding Single Sign-On (SSO) and SAML: Simplified
Favicon
When should I use JWTs?
Favicon
Bring your own sign-in UI to Logto Cloud
Favicon
Create a remark plugin to extract MDX reading time
Favicon
Everything you need to know about Base64
Favicon
How does the browser process the URL input in the address bar?
Favicon
Deep Linking AWS Console with all your AWS IAM Identity Center Roles
Favicon
Are You Prepared for the Next Cyber Attack? - IDArmor
Favicon
heaviside and Identity in PyTorch
Favicon
Is magic link sign-in dying? A closer look at its declining popularity
Favicon
Crafting Your Developer Identity: A Blueprint for 2024 🌟
Favicon
Use React.lazy with confidence: A safe way to load components when iterating fast
Favicon
Personal access tokens, machine-to-machine authentication, and API Keys definition and their real-world scenarios

Featured ones: