[Python] Piecewise curve segment lengths from Pytorch

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    Most examples of pdist (or cdist) seems to be between two tensors. If I have a piecewise curve defined as follows:

    line=torch.tensor([(-104.6400,0.0000),(-104.6400,0.1500),(-103.5500,0.5140),(-98.1000,1.0775),(-92.6500,1.4553)])


    what I have coded to get the segment lenghts is

    i=0
    for point in line:
    if i>0:
    print(f"{i}: {pdist(previous_point,point)}")
    previous_point = point
    i += 1


    Is this the best way or is there a more pytorchic way of doing it?

    Continue reading...

Compartilhe esta Página