快捷方式

torch.cross

torch.cross(input, other, dim=None, *, out=None) Tensor

返回 inputother 在維度 dim 上的向量的叉積。

支援 float、double、cfloat 和 cdouble dtypes 的輸入。也支援向量批次處理,它會沿著維度 dim 計算乘積。 在這種情況下,輸出具有與輸入相同的批次維度。

警告

如果沒有給定 dim,則預設為找到的第一個大小為 3 的維度。 請注意,這可能出乎意料。

此行為已被棄用,並將在未來版本中更改為與 torch.linalg.cross() 的行為相符。

另請參閱

torch.linalg.cross(),它的預設值為 dim=-1。

參數
  • input (Tensor) – 輸入張量。

  • other (Tensor) – 第二個輸入張量

  • dim (int, optional) – 要計算叉積的維度。

關鍵字參數

out (Tensor, optional) – 輸出張量。

範例

>>> a = torch.randn(4, 3)
>>> a
tensor([[-0.3956,  1.1455,  1.6895],
        [-0.5849,  1.3672,  0.3599],
        [-1.1626,  0.7180, -0.0521],
        [-0.1339,  0.9902, -2.0225]])
>>> b = torch.randn(4, 3)
>>> b
tensor([[-0.0257, -1.4725, -1.2251],
        [-1.1479, -0.7005, -1.9757],
        [-1.3904,  0.3726, -1.1836],
        [-0.9688, -0.7153,  0.2159]])
>>> torch.cross(a, b, dim=1)
tensor([[ 1.0844, -0.5281,  0.6120],
        [-2.4490, -1.5687,  1.9792],
        [-0.8304, -1.3037,  0.5650],
        [-1.2329,  1.9883,  1.0551]])
>>> torch.cross(a, b)
tensor([[ 1.0844, -0.5281,  0.6120],
        [-2.4490, -1.5687,  1.9792],
        [-0.8304, -1.3037,  0.5650],
        [-1.2329,  1.9883,  1.0551]])

文件

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources