torch.Tensor.Tensor.arccos_
Tensor.arccos_(): thisIn-place inverse cosine (arccosine).
Computes the inverse cosine (arccosine) of each element in-place. The input must be in the range [-1, 1] for real-valued outputs. Element-wise: y = arccos(x) where arccos returns values in [0, π].
Use Cases:
- Computing angles between vectors (via dot product)
- Signal reconstruction from cosine transforms
- Angular distance calculations
- Spherical coordinate transformations
- Input range: Input values must be in [-1, 1] for real output.
- Output range: Output is in [0, π] radians (always positive).
- In-place: Modifies tensor directly, more memory efficient.
- Alias: PyTorch calls this
acos_(), this is thearccos_()alias.
Returns
this– This tensor, modified in-placeExamples
const x = torch.tensor([1, 0, -1]);
x.arccos_(); // [0, π/2, π] ≈ [0, 1.571, 3.142]
// Angle between normalized vectors via dot product
const dotProduct = torch.tensor([0.8]);
const angle = dotProduct.clone().arccos_(); // Angle in radians
// Arccosine for all values in [-1, 1]
const values = torch.linspace(-1, 1, 5);
values.arccos_();
// Common angles
torch.tensor([1]).arccos_(); // 0
torch.tensor([0]).arccos_(); // π/2 ≈ 1.571
torch.tensor([-1]).arccos_(); // π ≈ 3.142