[Python] Stretching a list and calculating the in-between numbers in python [closed]

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

  1. Stack

    Stack Membro Participativo

    I'm trying to stretch a list:

    rough = [0, -14, -21, -25, -28, -31, -33, -35, -36, -36,-36, -34, -32, -29, -23, -15, -9, 0]

    into 300 items, with in-between values interpolated.

    The answers I can find usually involve lots of bells and whistles, plots, dataframes, colors, importing modules that I don't have installed. It's difficult to discern what the underlaying logic is.

    Since I'm trying to understand the math behind it, may I ask what's the simplest way of handling this kind of problem?

    I can imagine a function that takes the list, and the target count, then adding the values weighted by how far we are from them. But coming up with the math eludes me. Something like:

    def stretch_to(l, n):
    out = [0] * n
    m = len(l)
    for i, x in enumerate(l):
    out[i*(n-1)//(m-1)] = x

    return out


    But instead of zero, the values between actual numbers estimated to create a smooth curve.

    Continue reading...

Compartilhe esta Página