捷徑

torch.linalg.cross

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

計算兩個 3 維向量的叉積。

支援 float、double、cfloat 和 cdouble 資料型態的輸入。 也支援向量批次處理,並沿著維度 dim 計算叉積。 它會在批次維度上進行廣播。

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

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

  • dim (int, optional) – 計算叉積的維度。 預設值:-1

關鍵字引數

out (Tensor, optional) – 輸出張量。 如果為 None,則忽略。 預設值:None

範例

>>> 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.linalg.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]])
>>> a = torch.randn(1, 3)  # a is broadcast to match shape of b
>>> a
tensor([[-0.9941, -0.5132,  0.5681]])
>>> torch.linalg.cross(a, b)
tensor([[ 1.4653, -1.2325,  1.4507],
        [ 1.4119, -2.6163,  0.1073],
        [ 0.3957, -1.9666, -1.0840],
        [ 0.2956, -0.3357,  0.2139]])

文件

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