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.
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.
Share Improve this question asked Mar 12 at 22:56 mhoopermhooper 1038 bronze badges 2 |1 Answer
Reset to default -1So I had a coffee and found the a solution. This will create the array of values dependant on x and y.
import numpy as np
x = 5
y = 100
inputArray = np.zeros(x)
squares = [list(inputArray+i) for i in range(y)]
values = ','.join([f"{j}" for j in squares])
x-by-y
and the expected output? How x varies? – ThomasIsCoding Commented Mar 12 at 23:06x
,y
in your example. – furas Commented Mar 13 at 18:06