-1
new = []
curvepoints = []   
for i in range (0, 10):
    for j in range (0, 3):
        new.append(0)
        curvepoints.append(new)
    new = []

I have initialized my main array curvepoints using the above code

p = [-30, -23, -16, -9, -2, 5, 12, 19, 30] 

p is my 2nd array. I am trying to initialize every 1st element of curvepoint with element of p using the below code

for i in range(0,len(p)):
    print(curvepoints[c][0])
    curvepoints[c][0]=p[i]
    c = c+1

But it is initializing abruptly as follows:

[[-16, 0, 0], [-16, 0, 0], [-16, 0, 0], [5, 0, 0], [5, 0, 0], [5, 0, 0], [30, 0, 0], [30, 0, 0], [30, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]

Please do let me know how I can initialize only the 1st elements with p.

felipe
  • 7,324
  • 2
  • 28
  • 37
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – FairPluto Jan 18 '23 at 16:21

1 Answers1

0
p = [-30, -23, -16, -9, -2, 5, 12, 19, 30]
curvepoints = [[x, 0, 0] for x in p]

Which gives you:

[[-30, 0, 0], [-23, 0, 0], [-16, 0, 0], [-9, 0, 0], [-2, 0, 0], [5, 0, 0], [12, 0, 0], [19, 0, 0], [30, 0, 0]]
felipe
  • 7,324
  • 2
  • 28
  • 37