[Python] Creating a value array from a list with varying size

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

  1. Stack

    Stack Membro Participativo

    I have the need to create a function which takes an input list or numpy array and creates into a string. The issue is easy enough to compute when knowing the numbers and the particulars. Like in the simple function code below, we see a list with 2x 100 which I can create the string very simply. I know that there are only 2 variables and can join simply to create the values using a and b.

    squares = [(i, i) for i in range(100)]
    values = ",".join([f"({a}, {b})" for (a, b) in squares])


    Is there a way to create the values matrix if there was a np array with x by y dimensions? The y dimension will work through the loop easy enough, just the x. The x will change dependent on the particular need and list I am assessing - also the lists are variable with different types of data - mainly integers and floats.

    Continue reading...

Compartilhe esta Página